diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-09-21 17:05:35 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-09-21 17:05:35 +0200 |
commit | ff6ce422ddecb7dcb7fd9f67d3ea0cfdec7e74ea (patch) | |
tree | 8a66cc12d14da634984978aa387a92537d161915 /DevTools | |
parent | e4e92980a17449abb315e2267c897529f700525e (diff) | |
download | serenity-ff6ce422ddecb7dcb7fd9f67d3ea0cfdec7e74ea.zip |
LibGUI: Convert GWidget to ObjectPtr
Diffstat (limited to 'DevTools')
-rw-r--r-- | DevTools/Inspector/main.cpp | 2 | ||||
-rw-r--r-- | DevTools/VisualBuilder/VBPropertiesWindow.cpp | 2 | ||||
-rw-r--r-- | DevTools/VisualBuilder/VBWidget.cpp | 2 | ||||
-rw-r--r-- | DevTools/VisualBuilder/VBWidget.h | 4 | ||||
-rw-r--r-- | DevTools/VisualBuilder/VBWidgetRegistry.cpp | 12 | ||||
-rw-r--r-- | DevTools/VisualBuilder/VBWidgetRegistry.h | 6 | ||||
-rw-r--r-- | DevTools/VisualBuilder/main.cpp | 2 |
7 files changed, 15 insertions, 15 deletions
diff --git a/DevTools/Inspector/main.cpp b/DevTools/Inspector/main.cpp index 892f482acb..ed2d98f6f1 100644 --- a/DevTools/Inspector/main.cpp +++ b/DevTools/Inspector/main.cpp @@ -32,7 +32,7 @@ int main(int argc, char** argv) window->set_title("Inspector"); window->set_rect(150, 150, 300, 500); - auto* widget = new GWidget; + auto widget = GWidget::construct(); window->set_main_widget(widget); widget->set_fill_with_background_color(true); widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); diff --git a/DevTools/VisualBuilder/VBPropertiesWindow.cpp b/DevTools/VisualBuilder/VBPropertiesWindow.cpp index ff2759e5b7..78fceb2ced 100644 --- a/DevTools/VisualBuilder/VBPropertiesWindow.cpp +++ b/DevTools/VisualBuilder/VBPropertiesWindow.cpp @@ -55,7 +55,7 @@ VBPropertiesWindow::VBPropertiesWindow() set_title("Properties"); set_rect(780, 200, 240, 280); - auto* widget = new GWidget; + auto widget = GWidget::construct(); widget->set_fill_with_background_color(true); widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); widget->layout()->set_margins({ 2, 2, 2, 2 }); diff --git a/DevTools/VisualBuilder/VBWidget.cpp b/DevTools/VisualBuilder/VBWidget.cpp index f1b3a1879e..f1e341a1d8 100644 --- a/DevTools/VisualBuilder/VBWidget.cpp +++ b/DevTools/VisualBuilder/VBWidget.cpp @@ -30,7 +30,7 @@ VBWidget::~VBWidget() { m_form.m_gwidget_map.remove(m_gwidget); m_form.m_selected_widgets.remove(this); - delete m_gwidget; + m_gwidget->parent()->remove_child(*m_gwidget); } Rect VBWidget::rect() const diff --git a/DevTools/VisualBuilder/VBWidget.h b/DevTools/VisualBuilder/VBWidget.h index 793d15a44f..735e532afa 100644 --- a/DevTools/VisualBuilder/VBWidget.h +++ b/DevTools/VisualBuilder/VBWidget.h @@ -8,10 +8,10 @@ #include <AK/RefCounted.h> #include <AK/Weakable.h> #include <LibDraw/Rect.h> +#include <LibGUI/GWidget.h> class GPainter; class GVariant; -class GWidget; class VBForm; class VBProperty; class VBWidgetPropertyModel; @@ -81,7 +81,7 @@ private: VBWidgetType m_type { VBWidgetType::None }; VBForm& m_form; - GWidget* m_gwidget { nullptr }; + ObjectPtr<GWidget> m_gwidget; NonnullOwnPtrVector<VBProperty> m_properties; NonnullRefPtr<VBWidgetPropertyModel> m_property_model; Rect m_transform_origin_rect; diff --git a/DevTools/VisualBuilder/VBWidgetRegistry.cpp b/DevTools/VisualBuilder/VBWidgetRegistry.cpp index e3b9ca25a5..ef02c0a79a 100644 --- a/DevTools/VisualBuilder/VBWidgetRegistry.cpp +++ b/DevTools/VisualBuilder/VBWidgetRegistry.cpp @@ -68,11 +68,11 @@ VBWidgetType widget_type_from_class_name(const StringView& name) ASSERT_NOT_REACHED(); } -static GWidget* build_gwidget(VBWidgetType type, GWidget* parent) +static ObjectPtr<GWidget> build_gwidget(VBWidgetType type, GWidget* parent) { switch (type) { case VBWidgetType::GWidget: - return new GWidget(parent); + return GWidget::construct(parent); case VBWidgetType::GScrollBar: return GScrollBar::construct(Orientation::Vertical, parent); case VBWidgetType::GGroupBox: @@ -113,21 +113,21 @@ static GWidget* build_gwidget(VBWidgetType type, GWidget* parent) return slider; } case VBWidgetType::GCheckBox: { - auto* box = new GCheckBox(parent); + auto box = GCheckBox::construct(parent); box->set_text("checkbox_1"); return box; } case VBWidgetType::GRadioButton: - return new GRadioButton("radio_1", parent); + return GRadioButton::construct("radio_1", parent); default: ASSERT_NOT_REACHED(); return nullptr; } } -GWidget* VBWidgetRegistry::build_gwidget(VBWidget& widget, VBWidgetType type, GWidget* parent, NonnullOwnPtrVector<VBProperty>& properties) +ObjectPtr<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 property = make<VBProperty>(widget, name, value); property->set_readonly(true); diff --git a/DevTools/VisualBuilder/VBWidgetRegistry.h b/DevTools/VisualBuilder/VBWidgetRegistry.h index 2d30ed7831..93f1fb091b 100644 --- a/DevTools/VisualBuilder/VBWidgetRegistry.h +++ b/DevTools/VisualBuilder/VBWidgetRegistry.h @@ -1,12 +1,12 @@ #pragma once #include "VBWidgetType.h" -#include <AK/String.h> #include <AK/HashMap.h> #include <AK/NonnullOwnPtrVector.h> #include <AK/OwnPtr.h> +#include <AK/String.h> +#include <LibGUI/GWidget.h> -class GWidget; class VBProperty; class VBWidget; @@ -19,7 +19,7 @@ public: callback((VBWidgetType)i); } - static GWidget* build_gwidget(VBWidget&, VBWidgetType, GWidget* parent, NonnullOwnPtrVector<VBProperty>&); + static ObjectPtr<GWidget> build_gwidget(VBWidget&, VBWidgetType, GWidget* parent, NonnullOwnPtrVector<VBProperty>&); }; String to_class_name(VBWidgetType); diff --git a/DevTools/VisualBuilder/main.cpp b/DevTools/VisualBuilder/main.cpp index 986050abdb..1d314b8467 100644 --- a/DevTools/VisualBuilder/main.cpp +++ b/DevTools/VisualBuilder/main.cpp @@ -80,7 +80,7 @@ GWindow* make_toolbox_window() window->set_title("Widgets"); window->set_rect(20, 200, 80, 300); - auto* widget = new GWidget; + auto widget = GWidget::construct(); widget->set_fill_with_background_color(true); widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); widget->layout()->set_spacing(0); |