From df80265d3a6965524d681992df39271d71373a04 Mon Sep 17 00:00:00 2001 From: Yyf2333 <2514537033@qq.com> Date: Sat, 1 Feb 2025 20:29:40 +0800 Subject: [PATCH] Eliminate interior mutability in get_selected_node_list. --- editor/editor_data.cpp | 2 +- editor/editor_data.h | 2 +- editor/plugins/node_3d_editor_plugin.cpp | 46 ++++++++++++------------ editor/scene_tree_dock.cpp | 2 +- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 69ad7fe9923..a36a52c31ab 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -1329,7 +1329,7 @@ TypedArray EditorSelection::get_selected_nodes() { return ret; } -List &EditorSelection::get_selected_node_list() { +const List &EditorSelection::get_selected_node_list() { if (changed) { update(); } else { diff --git a/editor/editor_data.h b/editor/editor_data.h index 8d7e5512efd..5ce76f4462c 100644 --- a/editor/editor_data.h +++ b/editor/editor_data.h @@ -318,7 +318,7 @@ public: TypedArray get_selected_nodes(); // Returns only the top level selected nodes. // That is, if the selection includes some node and a child of that node, only the parent is returned. - List &get_selected_node_list(); + const List &get_selected_node_list(); // Returns all the selected nodes (list version of "get_selected_nodes"). List get_full_selected_node_list(); // Returns the map of selected objects and their metadata. diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index b241072ac5f..c7e07dba2bd 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -662,10 +662,10 @@ int Node3DEditorViewport::get_selected_count() const { } void Node3DEditorViewport::cancel_transform() { - List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_selected_node_list(); - for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->get()); + for (Node *E : selection) { + Node3D *sp = Object::cast_to(E); if (!sp) { continue; } @@ -1227,10 +1227,10 @@ void Node3DEditorViewport::_compute_edit(const Point2 &p_point) { se->original_local = selected->get_transform(); se->original = selected->get_global_transform(); } else { - List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_selected_node_list(); - for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->get()); + for (Node *E : selection) { + Node3D *sp = Object::cast_to(E); if (!sp) { continue; } @@ -2430,7 +2430,7 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { return; } - List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_selected_node_list(); for (Node *E : selection) { Node3D *sp = Object::cast_to(E); @@ -3173,7 +3173,7 @@ void Node3DEditorViewport::_notification(int p_what) { selected_node = ruler_start_point; } } else { - List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_selected_node_list(); if (selection.size() == 1) { selected_node = Object::cast_to(selection.front()->get()); } @@ -3566,7 +3566,7 @@ void Node3DEditorViewport::_menu_option(int p_option) { Transform3D camera_transform = camera->get_global_transform(); - List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_selected_node_list(); undo_redo->create_action(TTR("Align Transform with View")); @@ -3612,7 +3612,7 @@ void Node3DEditorViewport::_menu_option(int p_option) { Transform3D camera_transform = camera->get_global_transform(); - List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_selected_node_list(); undo_redo->create_action(TTR("Align Rotation with View")); for (Node *E : selection) { @@ -4419,7 +4419,7 @@ Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos, Node3D HashSet rids; if (!preview_node->is_inside_tree() && !ruler->is_inside_tree()) { - List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_selected_node_list(); Node3D *first_selected_node = Object::cast_to(selection.front()->get()); @@ -5078,10 +5078,10 @@ void Node3DEditorViewport::commit_transform() { EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); undo_redo->create_action(_transform_name[_edit.mode]); - List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_selected_node_list(); - for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->get()); + for (Node *E : selection) { + Node3D *sp = Object::cast_to(E); if (!sp) { continue; } @@ -5103,7 +5103,7 @@ void Node3DEditorViewport::commit_transform() { void Node3DEditorViewport::apply_transform(Vector3 p_motion, double p_snap) { bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); - List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_selected_node_list(); for (Node *E : selection) { Node3D *sp = Object::cast_to(E); if (!sp) { @@ -6297,9 +6297,9 @@ void Node3DEditor::update_transform_gizmo() { count++; } } else { - List &selection = editor_selection->get_selected_node_list(); - for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->get()); + const List &selection = editor_selection->get_selected_node_list(); + for (Node *E : selection) { + Node3D *sp = Object::cast_to(E); if (!sp) { continue; } @@ -6979,7 +6979,7 @@ void Node3DEditor::_menu_item_pressed(int p_option) { case MENU_LOCK_SELECTED: { undo_redo->create_action(TTR("Lock Selected")); - List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_selected_node_list(); for (Node *E : selection) { Node3D *spatial = Object::cast_to(E); @@ -7000,7 +7000,7 @@ void Node3DEditor::_menu_item_pressed(int p_option) { case MENU_UNLOCK_SELECTED: { undo_redo->create_action(TTR("Unlock Selected")); - List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_selected_node_list(); for (Node *E : selection) { Node3D *spatial = Object::cast_to(E); @@ -7021,7 +7021,7 @@ void Node3DEditor::_menu_item_pressed(int p_option) { case MENU_GROUP_SELECTED: { undo_redo->create_action(TTR("Group Selected")); - List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_selected_node_list(); for (Node *E : selection) { Node3D *spatial = Object::cast_to(E); @@ -7041,7 +7041,7 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_UNGROUP_SELECTED: { undo_redo->create_action(TTR("Ungroup Selected")); - List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_selected_node_list(); for (Node *E : selection) { Node3D *spatial = Object::cast_to(E); @@ -7957,7 +7957,7 @@ void Node3DEditor::_refresh_menu_icons() { bool all_grouped = true; bool has_node3d_item = false; - List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_selected_node_list(); if (selection.is_empty()) { all_locked = false; diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index d8f7c37faee..c45213cdc4c 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -1392,7 +1392,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } break; case TOOL_TOGGLE_SCENE_UNIQUE_NAME: { // Enabling/disabling based on the same node based on which the checkbox in the menu is checked/unchecked. - List::Element *first_selected = editor_selection->get_selected_node_list().front(); + const List::Element *first_selected = editor_selection->get_selected_node_list().front(); if (first_selected == nullptr) { return; }