1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

Style: Enforce braces around if blocks and loops

Using clang-tidy's `readability-braces-around-statements`.
https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
This commit is contained in:
Rémi Verschelde
2020-05-14 16:41:43 +02:00
parent 07bc4e2f96
commit 0ee0fa42e6
683 changed files with 22803 additions and 12225 deletions

View File

@@ -69,8 +69,9 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i
}
} else if (p_id == BUTTON_SCRIPT) {
Ref<Script> script_typed = n->get_script();
if (!script_typed.is_null())
if (!script_typed.is_null()) {
emit_signal("open_script", script_typed);
}
} else if (p_id == BUTTON_VISIBILITY) {
undo_redo->create_action(TTR("Toggle Visible"));
@@ -119,8 +120,9 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i
undo_redo->commit_action();
} else if (p_id == BUTTON_WARNING) {
String config_err = n->get_configuration_warning();
if (config_err == String())
if (config_err == String()) {
return;
}
config_err = config_err.word_wrap(80);
warning->set_text(config_err);
warning->popup_centered();
@@ -154,8 +156,9 @@ void SceneTreeEditor::_toggle_visible(Node *p_node) {
}
bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
if (!p_node)
if (!p_node) {
return false;
}
// only owned nodes are editable, since nodes can create their own (manually owned) child nodes,
// which the editor needs not to know about.
@@ -176,14 +179,16 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
TreeItem *item = tree->create_item(p_parent);
item->set_text(0, p_node->get_name());
if (can_rename && !part_of_subscene)
if (can_rename && !part_of_subscene) {
item->set_editable(0, true);
}
item->set_selectable(0, true);
if (can_rename) {
bool collapsed = p_node->is_displayed_folded();
if (collapsed)
if (collapsed) {
item->set_collapsed(true);
}
}
Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(p_node, "Node");
@@ -310,8 +315,9 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
if (can_open_instance && undo_redo) { //Show buttons only when necessary(SceneTreeDock) to avoid crashes
if (!p_node->is_connected("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed)))
if (!p_node->is_connected("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed))) {
p_node->connect("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed), varray(p_node));
}
Ref<Script> script = p_node->get_script();
if (!script.is_null()) {
@@ -323,40 +329,48 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
if (p_node->is_class("CanvasItem")) {
bool is_locked = p_node->has_meta("_edit_lock_"); //_edit_group_
if (is_locked)
if (is_locked) {
item->add_button(0, get_theme_icon("Lock", "EditorIcons"), BUTTON_LOCK, false, TTR("Node is locked.\nClick to unlock it."));
}
bool is_grouped = p_node->has_meta("_edit_group_");
if (is_grouped)
if (is_grouped) {
item->add_button(0, get_theme_icon("Group", "EditorIcons"), BUTTON_GROUP, false, TTR("Children are not selectable.\nClick to make selectable."));
}
bool v = p_node->call("is_visible");
if (v)
if (v) {
item->add_button(0, get_theme_icon("GuiVisibilityVisible", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
else
} else {
item->add_button(0, get_theme_icon("GuiVisibilityHidden", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
}
if (!p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed)))
if (!p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed))) {
p_node->connect("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed), varray(p_node));
}
_update_visibility_color(p_node, item);
} else if (p_node->is_class("Node3D")) {
bool is_locked = p_node->has_meta("_edit_lock_");
if (is_locked)
if (is_locked) {
item->add_button(0, get_theme_icon("Lock", "EditorIcons"), BUTTON_LOCK, false, TTR("Node is locked.\nClick to unlock it."));
}
bool is_grouped = p_node->has_meta("_edit_group_");
if (is_grouped)
if (is_grouped) {
item->add_button(0, get_theme_icon("Group", "EditorIcons"), BUTTON_GROUP, false, TTR("Children are not selectable.\nClick to make selectable."));
}
bool v = p_node->call("is_visible");
if (v)
if (v) {
item->add_button(0, get_theme_icon("GuiVisibilityVisible", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
else
} else {
item->add_button(0, get_theme_icon("GuiVisibilityHidden", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
}
if (!p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed)))
if (!p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed))) {
p_node->connect("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed), varray(p_node));
}
_update_visibility_color(p_node, item);
} else if (p_node->is_class("AnimationPlayer")) {
@@ -375,8 +389,9 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
}
if (selected == p_node) {
if (!editor_selection)
if (!editor_selection) {
item->select(0);
}
item->set_as_cursor(0);
}
@@ -441,10 +456,11 @@ void SceneTreeEditor::_node_visibility_changed(Node *p_node) {
visible = p_node->call("is_visible");
}
if (visible)
if (visible) {
item->set_button(0, idx, get_theme_icon("GuiVisibilityVisible", "EditorIcons"));
else
} else {
item->set_button(0, idx, get_theme_icon("GuiVisibilityHidden", "EditorIcons"));
}
_update_visibility_color(p_node, item);
}
@@ -462,23 +478,27 @@ void SceneTreeEditor::_update_visibility_color(Node *p_node, TreeItem *p_item) {
}
void SceneTreeEditor::_node_script_changed(Node *p_node) {
if (tree_dirty)
if (tree_dirty) {
return;
}
MessageQueue::get_singleton()->push_call(this, "_update_tree");
tree_dirty = true;
}
void SceneTreeEditor::_node_removed(Node *p_node) {
if (EditorNode::get_singleton()->is_exiting())
if (EditorNode::get_singleton()->is_exiting()) {
return; //speed up exit
}
if (p_node->is_connected("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed)))
if (p_node->is_connected("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed))) {
p_node->disconnect("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed));
}
if (p_node->is_class("Node3D") || p_node->is_class("CanvasItem")) {
if (p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed)))
if (p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed))) {
p_node->disconnect("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed));
}
}
if (p_node == selected) {
@@ -516,8 +536,9 @@ void SceneTreeEditor::_update_tree() {
void SceneTreeEditor::_compute_hash(Node *p_node, uint64_t &hash) {
hash = hash_djb2_one_64(p_node->get_instance_id(), hash);
if (p_node->get_parent())
if (p_node->get_parent()) {
hash = hash_djb2_one_64(p_node->get_parent()->get_instance_id(), hash); //so a reparent still produces a different hash
}
for (int i = 0; i < p_node->get_child_count(); i++) {
_compute_hash(p_node->get_child(i), hash);
@@ -527,30 +548,37 @@ void SceneTreeEditor::_compute_hash(Node *p_node, uint64_t &hash) {
void SceneTreeEditor::_test_update_tree() {
pending_test_update = false;
if (!is_inside_tree())
if (!is_inside_tree()) {
return;
}
if (tree_dirty)
if (tree_dirty) {
return; // don't even bother
}
uint64_t hash = hash_djb2_one_64(0);
if (get_scene_node())
if (get_scene_node()) {
_compute_hash(get_scene_node(), hash);
}
//test hash
if (hash == last_hash)
if (hash == last_hash) {
return; // did not change
}
MessageQueue::get_singleton()->push_call(this, "_update_tree");
tree_dirty = true;
}
void SceneTreeEditor::_tree_changed() {
if (EditorNode::get_singleton()->is_exiting())
if (EditorNode::get_singleton()->is_exiting()) {
return; //speed up exit
if (pending_test_update)
}
if (pending_test_update) {
return;
if (tree_dirty)
}
if (tree_dirty) {
return;
}
MessageQueue::get_singleton()->push_call(this, "_test_update_tree");
pending_test_update = true;
@@ -563,8 +591,9 @@ void SceneTreeEditor::_selected_changed() {
Node *n = get_node(np);
if (n == selected)
if (n == selected) {
return;
}
selected = get_node(np);
@@ -589,11 +618,13 @@ void SceneTreeEditor::_cell_multi_selected(Object *p_object, int p_cell, bool p_
Node *n = get_node(np);
if (!n)
if (!n) {
return;
}
if (!editor_selection)
if (!editor_selection) {
return;
}
if (p_selected) {
editor_selection->add_node(n);
@@ -630,18 +661,21 @@ void SceneTreeEditor::_notification(int p_what) {
}
TreeItem *SceneTreeEditor::_find(TreeItem *p_node, const NodePath &p_path) {
if (!p_node)
if (!p_node) {
return nullptr;
}
NodePath np = p_node->get_metadata(0);
if (np == p_path)
if (np == p_path) {
return p_node;
}
TreeItem *children = p_node->get_children();
while (children) {
TreeItem *n = _find(children, p_path);
if (n)
if (n) {
return n;
}
children = children->get_next();
}
@@ -651,13 +685,16 @@ TreeItem *SceneTreeEditor::_find(TreeItem *p_node, const NodePath &p_path) {
void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) {
ERR_FAIL_COND(blocked > 0);
if (pending_test_update)
if (pending_test_update) {
_test_update_tree();
if (tree_dirty)
}
if (tree_dirty) {
_update_tree();
}
if (selected == p_node)
if (selected == p_node) {
return;
}
TreeItem *item = p_node ? _find(tree->get_root(), p_node->get_path()) : nullptr;
@@ -674,8 +711,9 @@ void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) {
tree->ensure_cursor_is_visible();
} else {
if (!p_node)
if (!p_node) {
selected = nullptr;
}
_update_tree();
selected = p_node;
}
@@ -726,8 +764,9 @@ void SceneTreeEditor::_renamed() {
which->set_text(0, new_name);
}
if (new_name == n->get_name())
if (new_name == n->get_name()) {
return;
}
if (!undo_redo) {
n->set_name(new_name);
@@ -747,8 +786,9 @@ Node *SceneTreeEditor::get_selected() {
}
void SceneTreeEditor::set_marked(const Set<Node *> &p_marked, bool p_selectable, bool p_children_selectable) {
if (tree_dirty)
if (tree_dirty) {
_update_tree();
}
marked = p_marked;
marked_selectable = p_selectable;
marked_children_selectable = p_children_selectable;
@@ -757,8 +797,9 @@ void SceneTreeEditor::set_marked(const Set<Node *> &p_marked, bool p_selectable,
void SceneTreeEditor::set_marked(Node *p_marked, bool p_selectable, bool p_children_selectable) {
Set<Node *> s;
if (p_marked)
if (p_marked) {
s.insert(p_marked);
}
set_marked(s, p_selectable, p_children_selectable);
}
@@ -796,18 +837,21 @@ void SceneTreeEditor::_update_selection(TreeItem *item) {
NodePath np = item->get_metadata(0);
if (!has_node(np))
if (!has_node(np)) {
return;
}
Node *n = get_node(np);
if (!n)
if (!n) {
return;
}
if (editor_selection->is_selected(n))
if (editor_selection->is_selected(n)) {
item->select(0);
else
} else {
item->deselect(0);
}
TreeItem *c = item->get_children();
@@ -818,25 +862,30 @@ void SceneTreeEditor::_update_selection(TreeItem *item) {
}
void SceneTreeEditor::_selection_changed() {
if (!editor_selection)
if (!editor_selection) {
return;
}
TreeItem *root = tree->get_root();
if (!root)
if (!root) {
return;
}
_update_selection(root);
}
void SceneTreeEditor::_cell_collapsed(Object *p_obj) {
if (updating_tree)
if (updating_tree) {
return;
if (!can_rename)
}
if (!can_rename) {
return;
}
TreeItem *ti = Object::cast_to<TreeItem>(p_obj);
if (!ti)
if (!ti) {
return;
}
bool collapsed = ti->is_collapsed();
@@ -849,8 +898,9 @@ void SceneTreeEditor::_cell_collapsed(Object *p_obj) {
}
Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
if (!can_rename)
if (!can_rename) {
return Variant(); //not editable tree
}
Vector<Node *> selected;
Vector<Ref<Texture2D>> icons;
@@ -869,8 +919,9 @@ Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from
next = tree->get_next_selected(next);
}
if (selected.empty())
if (selected.empty()) {
return Variant();
}
VBoxContainer *vb = memnew(VBoxContainer);
Array objs;
@@ -910,28 +961,34 @@ bool SceneTreeEditor::_is_script_type(const StringName &p_type) const {
}
bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
if (!can_rename)
if (!can_rename) {
return false; //not editable tree
if (filter != String())
}
if (filter != String()) {
return false; //can't rearrange tree with filter turned on
}
Dictionary d = p_data;
if (!d.has("type"))
if (!d.has("type")) {
return false;
}
TreeItem *item = tree->get_item_at_position(p_point);
if (!item)
if (!item) {
return false;
}
int section = tree->get_drop_section_at_position(p_point);
if (section < -1 || (section == -1 && !item->get_parent()))
if (section < -1 || (section == -1 && !item->get_parent())) {
return false;
}
if (String(d["type"]) == "files") {
Vector<String> files = d["files"];
if (files.size() == 0)
if (files.size() == 0) {
return false; //weird
}
if (_is_script_type(EditorFileSystem::get_singleton()->get_file_type(files[0]))) {
tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
@@ -941,8 +998,9 @@ bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_d
for (int i = 0; i < files.size(); i++) {
String file = files[i];
String ftype = EditorFileSystem::get_singleton()->get_file_type(file);
if (ftype != "PackedScene")
if (ftype != "PackedScene") {
return false;
}
}
tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN | Tree::DROP_MODE_ON_ITEM); //so it works..
@@ -965,20 +1023,24 @@ bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_d
}
void SceneTreeEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
if (!can_drop_data_fw(p_point, p_data, p_from))
if (!can_drop_data_fw(p_point, p_data, p_from)) {
return;
}
TreeItem *item = tree->get_item_at_position(p_point);
if (!item)
if (!item) {
return;
}
int section = tree->get_drop_section_at_position(p_point);
if (section < -1)
if (section < -1) {
return;
}
NodePath np = item->get_metadata(0);
Node *n = get_node(np);
if (!n)
if (!n) {
return;
}
Dictionary d = p_data;
@@ -1131,8 +1193,9 @@ SceneTreeEditor::~SceneTreeEditor() {
void SceneTreeDialog::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: {
if (is_visible())
if (is_visible()) {
tree->update_tree();
}
} break;
case NOTIFICATION_ENTER_TREE: {
connect("confirmed", callable_mp(this, &SceneTreeDialog::_select));