VisualBuilder: Use NonnullRefPtrVector.

This commit is contained in:
Andreas Kling 2019-06-27 13:49:26 +02:00
parent d403e56494
commit 65e470c90a
Notes: sideshowbarker 2024-07-19 13:28:18 +09:00
2 changed files with 10 additions and 10 deletions

View file

@ -89,9 +89,9 @@ void VBForm::second_paint_event(GPaintEvent& event)
painter.add_clip_rect(event.rect());
for (auto& widget : m_widgets) {
if (widget->is_selected()) {
for_each_direction([&](Direction direction) {
painter.fill_rect(widget->grabber_rect(direction), Color::Black);
if (widget.is_selected()) {
for_each_direction([&](auto direction) {
painter.fill_rect(widget.grabber_rect(direction), Color::Black);
});
}
}
@ -128,19 +128,19 @@ void VBForm::keydown_event(GKeyEvent& event)
if (m_widgets.is_empty())
return;
if (m_selected_widgets.is_empty()) {
set_single_selected_widget(m_widgets.first());
set_single_selected_widget(&m_widgets.first());
update();
return;
}
int selected_widget_index = 0;
for (; selected_widget_index < m_widgets.size(); ++selected_widget_index) {
if (m_widgets[selected_widget_index] == *m_selected_widgets.begin())
if (&m_widgets[selected_widget_index] == *m_selected_widgets.begin())
break;
}
++selected_widget_index;
if (selected_widget_index == m_widgets.size())
selected_widget_index = 0;
set_single_selected_widget(m_widgets[selected_widget_index]);
set_single_selected_widget(&m_widgets[selected_widget_index]);
update();
return;
}
@ -318,7 +318,7 @@ void VBForm::write_to_file(const String& path)
JsonArray widget_array;
for (auto& widget : m_widgets) {
JsonObject widget_object;
widget->for_each_property([&](auto& property) {
widget.for_each_property([&](auto& property) {
if (property.value().is_bool())
widget_object.set(property.name(), property.value().to_bool());
else if (property.value().is_int())
@ -340,7 +340,7 @@ void VBForm::dump()
int i = 0;
for (auto& widget : m_widgets) {
dbgprintf("[Widget %d]\n", i++);
widget->for_each_property([](auto& property) {
widget.for_each_property([](auto& property) {
dbgprintf("%s=%s\n", property.name().characters(), property.value().to_string().characters());
});
dbgprintf("\n");

View file

@ -1,7 +1,7 @@
#pragma once
#include "VBWidget.h"
#include <AK/Vector.h>
#include <AK/NonnullRefPtrVector.h>
#include <LibGUI/GWidget.h>
class VBForm : public GWidget {
@ -52,7 +52,7 @@ private:
String m_name;
int m_grid_size { 5 };
bool m_should_snap_to_grid { true };
Vector<NonnullRefPtr<VBWidget>> m_widgets;
NonnullRefPtrVector<VBWidget> m_widgets;
HashMap<GWidget*, VBWidget*> m_gwidget_map;
HashTable<VBWidget*> m_selected_widgets;
Point m_transform_event_origin;