Skip to content

Commit 523b7fe

Browse files
committed
Merge pull request #102282 from YYF233333/dangerous_sig
Eliminate interior mutability in `get_selected_node_list`
2 parents 49fcd4c + df80265 commit 523b7fe

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

editor/editor_data.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ TypedArray<Node> EditorSelection::get_selected_nodes() {
13291329
return ret;
13301330
}
13311331

1332-
List<Node *> &EditorSelection::get_selected_node_list() {
1332+
const List<Node *> &EditorSelection::get_selected_node_list() {
13331333
if (changed) {
13341334
update();
13351335
} else {

editor/editor_data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ class EditorSelection : public Object {
318318
TypedArray<Node> get_selected_nodes();
319319
// Returns only the top level selected nodes.
320320
// That is, if the selection includes some node and a child of that node, only the parent is returned.
321-
List<Node *> &get_selected_node_list();
321+
const List<Node *> &get_selected_node_list();
322322
// Returns all the selected nodes (list version of "get_selected_nodes").
323323
List<Node *> get_full_selected_node_list();
324324
// Returns the map of selected objects and their metadata.

editor/plugins/node_3d_editor_plugin.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,10 @@ int Node3DEditorViewport::get_selected_count() const {
662662
}
663663

664664
void Node3DEditorViewport::cancel_transform() {
665-
List<Node *> &selection = editor_selection->get_selected_node_list();
665+
const List<Node *> &selection = editor_selection->get_selected_node_list();
666666

667-
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
668-
Node3D *sp = Object::cast_to<Node3D>(E->get());
667+
for (Node *E : selection) {
668+
Node3D *sp = Object::cast_to<Node3D>(E);
669669
if (!sp) {
670670
continue;
671671
}
@@ -1227,10 +1227,10 @@ void Node3DEditorViewport::_compute_edit(const Point2 &p_point) {
12271227
se->original_local = selected->get_transform();
12281228
se->original = selected->get_global_transform();
12291229
} else {
1230-
List<Node *> &selection = editor_selection->get_selected_node_list();
1230+
const List<Node *> &selection = editor_selection->get_selected_node_list();
12311231

1232-
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
1233-
Node3D *sp = Object::cast_to<Node3D>(E->get());
1232+
for (Node *E : selection) {
1233+
Node3D *sp = Object::cast_to<Node3D>(E);
12341234
if (!sp) {
12351235
continue;
12361236
}
@@ -2430,7 +2430,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
24302430
return;
24312431
}
24322432

2433-
List<Node *> &selection = editor_selection->get_selected_node_list();
2433+
const List<Node *> &selection = editor_selection->get_selected_node_list();
24342434

24352435
for (Node *E : selection) {
24362436
Node3D *sp = Object::cast_to<Node3D>(E);
@@ -3173,7 +3173,7 @@ void Node3DEditorViewport::_notification(int p_what) {
31733173
selected_node = ruler_start_point;
31743174
}
31753175
} else {
3176-
List<Node *> &selection = editor_selection->get_selected_node_list();
3176+
const List<Node *> &selection = editor_selection->get_selected_node_list();
31773177
if (selection.size() == 1) {
31783178
selected_node = Object::cast_to<Node3D>(selection.front()->get());
31793179
}
@@ -3566,7 +3566,7 @@ void Node3DEditorViewport::_menu_option(int p_option) {
35663566

35673567
Transform3D camera_transform = camera->get_global_transform();
35683568

3569-
List<Node *> &selection = editor_selection->get_selected_node_list();
3569+
const List<Node *> &selection = editor_selection->get_selected_node_list();
35703570

35713571
undo_redo->create_action(TTR("Align Transform with View"));
35723572

@@ -3612,7 +3612,7 @@ void Node3DEditorViewport::_menu_option(int p_option) {
36123612

36133613
Transform3D camera_transform = camera->get_global_transform();
36143614

3615-
List<Node *> &selection = editor_selection->get_selected_node_list();
3615+
const List<Node *> &selection = editor_selection->get_selected_node_list();
36163616

36173617
undo_redo->create_action(TTR("Align Rotation with View"));
36183618
for (Node *E : selection) {
@@ -4419,7 +4419,7 @@ Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos, Node3D
44194419
HashSet<RID> rids;
44204420

44214421
if (!preview_node->is_inside_tree() && !ruler->is_inside_tree()) {
4422-
List<Node *> &selection = editor_selection->get_selected_node_list();
4422+
const List<Node *> &selection = editor_selection->get_selected_node_list();
44234423

44244424
Node3D *first_selected_node = Object::cast_to<Node3D>(selection.front()->get());
44254425

@@ -5078,10 +5078,10 @@ void Node3DEditorViewport::commit_transform() {
50785078
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
50795079
undo_redo->create_action(_transform_name[_edit.mode]);
50805080

5081-
List<Node *> &selection = editor_selection->get_selected_node_list();
5081+
const List<Node *> &selection = editor_selection->get_selected_node_list();
50825082

5083-
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
5084-
Node3D *sp = Object::cast_to<Node3D>(E->get());
5083+
for (Node *E : selection) {
5084+
Node3D *sp = Object::cast_to<Node3D>(E);
50855085
if (!sp) {
50865086
continue;
50875087
}
@@ -5103,7 +5103,7 @@ void Node3DEditorViewport::commit_transform() {
51035103

51045104
void Node3DEditorViewport::apply_transform(Vector3 p_motion, double p_snap) {
51055105
bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW);
5106-
List<Node *> &selection = editor_selection->get_selected_node_list();
5106+
const List<Node *> &selection = editor_selection->get_selected_node_list();
51075107
for (Node *E : selection) {
51085108
Node3D *sp = Object::cast_to<Node3D>(E);
51095109
if (!sp) {
@@ -6297,9 +6297,9 @@ void Node3DEditor::update_transform_gizmo() {
62976297
count++;
62986298
}
62996299
} else {
6300-
List<Node *> &selection = editor_selection->get_selected_node_list();
6301-
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
6302-
Node3D *sp = Object::cast_to<Node3D>(E->get());
6300+
const List<Node *> &selection = editor_selection->get_selected_node_list();
6301+
for (Node *E : selection) {
6302+
Node3D *sp = Object::cast_to<Node3D>(E);
63036303
if (!sp) {
63046304
continue;
63056305
}
@@ -6979,7 +6979,7 @@ void Node3DEditor::_menu_item_pressed(int p_option) {
69796979
case MENU_LOCK_SELECTED: {
69806980
undo_redo->create_action(TTR("Lock Selected"));
69816981

6982-
List<Node *> &selection = editor_selection->get_selected_node_list();
6982+
const List<Node *> &selection = editor_selection->get_selected_node_list();
69836983

69846984
for (Node *E : selection) {
69856985
Node3D *spatial = Object::cast_to<Node3D>(E);
@@ -7000,7 +7000,7 @@ void Node3DEditor::_menu_item_pressed(int p_option) {
70007000
case MENU_UNLOCK_SELECTED: {
70017001
undo_redo->create_action(TTR("Unlock Selected"));
70027002

7003-
List<Node *> &selection = editor_selection->get_selected_node_list();
7003+
const List<Node *> &selection = editor_selection->get_selected_node_list();
70047004

70057005
for (Node *E : selection) {
70067006
Node3D *spatial = Object::cast_to<Node3D>(E);
@@ -7021,7 +7021,7 @@ void Node3DEditor::_menu_item_pressed(int p_option) {
70217021
case MENU_GROUP_SELECTED: {
70227022
undo_redo->create_action(TTR("Group Selected"));
70237023

7024-
List<Node *> &selection = editor_selection->get_selected_node_list();
7024+
const List<Node *> &selection = editor_selection->get_selected_node_list();
70257025

70267026
for (Node *E : selection) {
70277027
Node3D *spatial = Object::cast_to<Node3D>(E);
@@ -7041,7 +7041,7 @@ void Node3DEditor::_menu_item_pressed(int p_option) {
70417041
} break;
70427042
case MENU_UNGROUP_SELECTED: {
70437043
undo_redo->create_action(TTR("Ungroup Selected"));
7044-
List<Node *> &selection = editor_selection->get_selected_node_list();
7044+
const List<Node *> &selection = editor_selection->get_selected_node_list();
70457045

70467046
for (Node *E : selection) {
70477047
Node3D *spatial = Object::cast_to<Node3D>(E);
@@ -7957,7 +7957,7 @@ void Node3DEditor::_refresh_menu_icons() {
79577957
bool all_grouped = true;
79587958
bool has_node3d_item = false;
79597959

7960-
List<Node *> &selection = editor_selection->get_selected_node_list();
7960+
const List<Node *> &selection = editor_selection->get_selected_node_list();
79617961

79627962
if (selection.is_empty()) {
79637963
all_locked = false;

editor/scene_tree_dock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
13921392
} break;
13931393
case TOOL_TOGGLE_SCENE_UNIQUE_NAME: {
13941394
// Enabling/disabling based on the same node based on which the checkbox in the menu is checked/unchecked.
1395-
List<Node *>::Element *first_selected = editor_selection->get_selected_node_list().front();
1395+
const List<Node *>::Element *first_selected = editor_selection->get_selected_node_list().front();
13961396
if (first_selected == nullptr) {
13971397
return;
13981398
}

0 commit comments

Comments
 (0)