diff options
author | Dalai Felinto <dalai@blender.org> | 2020-04-03 20:15:01 +0300 |
---|---|---|
committer | Dalai Felinto <dalai@blender.org> | 2020-04-03 20:27:46 +0300 |
commit | d138cbfb47e379edc1ee915a8c6ff65b01f000d6 (patch) | |
tree | f4773ecce897c32eaf75295dd5f6a8e730d471ed /source/blender/editors/space_outliner | |
parent | b0c1184875d39abac4a65a5d20e263ea6d841009 (diff) |
Code Quality: Replace for loops with LISTBASE_FOREACH
Note this only changes cases where the variable was declared inside
the for loop. To handle it outside as well is a different challenge.
Differential Revision: https://developer.blender.org/D7320
Diffstat (limited to 'source/blender/editors/space_outliner')
9 files changed, 46 insertions, 54 deletions
diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c index 8563b7d8c24..5a0ed954909 100644 --- a/source/blender/editors/space_outliner/outliner_collections.c +++ b/source/blender/editors/space_outliner/outliner_collections.c @@ -336,8 +336,7 @@ static int collection_delete_exec(bContext *C, wmOperator *op) skip = true; } else { - for (CollectionParent *cparent = collection->parents.first; cparent; - cparent = cparent->next) { + LISTBASE_FOREACH (CollectionParent *, cparent, &collection->parents) { Collection *parent = cparent->collection; if (ID_IS_LINKED(parent)) { skip = true; @@ -848,7 +847,7 @@ static bool collections_indirect_only_clear_poll(bContext *C) static void layer_collection_flag_recursive_set(LayerCollection *lc, int flag) { - for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) { + LISTBASE_FOREACH (LayerCollection *, nlc, &lc->layer_collections) { if (lc->flag & flag) { nlc->flag |= flag; } @@ -1468,14 +1467,13 @@ static int outliner_unhide_all_exec(bContext *C, wmOperator *UNUSED(op)) /* Unhide all the collections. */ LayerCollection *lc_master = view_layer->layer_collections.first; - for (LayerCollection *lc_iter = lc_master->layer_collections.first; lc_iter; - lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_master->layer_collections) { lc_iter->flag &= ~LAYER_COLLECTION_HIDE; layer_collection_flag_recursive_set(lc_iter, LAYER_COLLECTION_HIDE); } /* Unhide all objects. */ - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { base->flag &= ~BASE_HIDDEN; } diff --git a/source/blender/editors/space_outliner/outliner_dragdrop.c b/source/blender/editors/space_outliner/outliner_dragdrop.c index 6f071ca128e..b6f5ac25c3c 100644 --- a/source/blender/editors/space_outliner/outliner_dragdrop.c +++ b/source/blender/editors/space_outliner/outliner_dragdrop.c @@ -263,8 +263,7 @@ static bool parent_drop_allowed(TreeElement *te, Object *potential_child) * element for object it means that all displayed objects belong to * active scene and parenting them is allowed (sergey) */ if (scene) { - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { if (BKE_view_layer_base_find(view_layer, potential_child)) { return true; } @@ -481,7 +480,7 @@ static int parent_clear_invoke(bContext *C, wmOperator *UNUSED(op), const wmEven ListBase *lb = event->customdata; wmDrag *drag = lb->first; - for (wmDragID *drag_id = drag->ids.first; drag_id; drag_id = drag_id->next) { + LISTBASE_FOREACH (wmDragID *, drag_id, &drag->ids) { if (GS(drag_id->id->name) == ID_OB) { Object *object = (Object *)drag_id->id; @@ -548,8 +547,7 @@ static int scene_drop_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent BKE_collection_object_add(bmain, collection, ob); - for (ViewLayer *view_layer = scene->view_layers.first; view_layer; - view_layer = view_layer->next) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { Base *base = BKE_view_layer_base_find(view_layer, ob); if (base) { ED_object_base_select(base, BA_SELECT); @@ -817,7 +815,7 @@ static int collection_drop_invoke(bContext *C, wmOperator *UNUSED(op), const wmE TREESTORE(data.te)->flag &= ~TSE_CLOSED; } - for (wmDragID *drag_id = drag->ids.first; drag_id; drag_id = drag_id->next) { + LISTBASE_FOREACH (wmDragID *, drag_id, &drag->ids) { /* Ctrl enables linking, so we don't need a from collection then. */ Collection *from = (event->ctrl) ? NULL : collection_parent_from_ID(drag_id->from_parent); diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index 3c569a71e93..ce83cfc3c97 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -91,7 +91,7 @@ static void outliner_tree_dimensions_impl(SpaceOutliner *soops, int *width, int *height) { - for (TreeElement *te = lb->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, lb) { *width = MAX2(*width, te->xend); if (height != NULL) { *height += UI_UNIT_Y; @@ -387,8 +387,7 @@ static void outliner_collection_set_flag_recursive(Scene *scene, if (base_or_object_prop) { /* Note: We can't use BKE_collection_object_cache_get() * otherwise we would not take collection exclusion into account. */ - for (CollectionObject *cob = layer_collection->collection->gobject.first; cob; - cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &layer_collection->collection->gobject) { outliner_base_or_object_pointer_create(view_layer, collection, cob->ob, &ptr); RNA_property_boolean_set(&ptr, base_or_object_prop, value); @@ -401,7 +400,7 @@ static void outliner_collection_set_flag_recursive(Scene *scene, /* Keep going recursively. */ ListBase *lb = (layer_collection ? &layer_collection->layer_collections : &collection->children); - for (Link *link = lb->first; link; link = link->next) { + LISTBASE_FOREACH (Link *, link, lb) { LayerCollection *layer_collection_iter = layer_collection ? (LayerCollection *)link : NULL; Collection *collection_iter = layer_collection ? (collection ? layer_collection_iter->collection : NULL) : @@ -467,7 +466,7 @@ static bool outliner_collection_is_isolated(Scene *scene, /* Keep going recursively. */ ListBase *lb = (layer_collection ? &layer_collection->layer_collections : &collection->children); - for (Link *link = lb->first; link; link = link->next) { + LISTBASE_FOREACH (Link *, link, lb) { LayerCollection *layer_collection_iter = layer_collection ? (LayerCollection *)link : NULL; Collection *collection_iter = layer_collection ? (collection ? layer_collection_iter->collection : NULL) : @@ -542,8 +541,7 @@ void outliner_collection_isolate_flag(Scene *scene, /* Make this collection direct parents also "visible". */ if (layer_collection) { LayerCollection *lc_parent = layer_collection; - for (LayerCollection *lc_iter = top_layer_collection->layer_collections.first; lc_iter; - lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &top_layer_collection->layer_collections) { if (BKE_layer_collection_has_layer_collection(lc_iter, layer_collection)) { lc_parent = lc_iter; break; @@ -555,8 +553,7 @@ void outliner_collection_isolate_flag(Scene *scene, scene, lc_parent, collection ? lc_parent->collection : NULL, &ptr); RNA_property_boolean_set(&ptr, layer_or_collection_prop, !is_hide); - for (LayerCollection *lc_iter = lc_parent->layer_collections.first; lc_iter; - lc_iter = lc_iter->next) { + LISTBASE_FOREACH (LayerCollection *, lc_iter, &lc_parent->layer_collections) { if (BKE_layer_collection_has_layer_collection(lc_iter, layer_collection)) { lc_parent = lc_iter; break; @@ -1054,7 +1051,7 @@ static void outliner_draw_restrictbuts(uiBlock *block, /* Create buttons. */ uiBut *bt; - for (TreeElement *te = lb->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, lb) { TreeStoreElem *tselem = TREESTORE(te); RestrictPropertiesActive props_active = props_active_parent; @@ -1651,7 +1648,7 @@ static void outliner_draw_userbuts(uiBlock *block, ListBase *lb) { - for (TreeElement *te = lb->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, lb) { TreeStoreElem *tselem = TREESTORE(te); if (te->ys + 2 * UI_UNIT_Y >= region->v2d.cur.ymin && te->ys <= region->v2d.cur.ymax) { if (tselem->type == 0) { @@ -1770,7 +1767,7 @@ static void outliner_draw_rnabuts( PointerRNA *ptr; PropertyRNA *prop; - for (TreeElement *te = lb->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, lb) { TreeStoreElem *tselem = TREESTORE(te); if (te->ys + 2 * UI_UNIT_Y >= region->v2d.cur.ymin && te->ys <= region->v2d.cur.ymax) { if (tselem->type == TSE_RNA_PROPERTY) { @@ -2861,7 +2858,7 @@ static void outliner_draw_iconrow(bContext *C, { eOLDrawState active = OL_DRAWSEL_NONE; - for (TreeElement *te = lb->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, lb) { TreeStoreElem *tselem = TREESTORE(te); /* object hierarchy always, further constrained on level */ @@ -3204,7 +3201,7 @@ static void outliner_draw_tree_element(bContext *C, if (TSELEM_OPEN(tselem, soops)) { *starty -= UI_UNIT_Y; - for (TreeElement *ten = te->subtree.first; ten; ten = ten->next) { + LISTBASE_FOREACH (TreeElement *, ten, &te->subtree) { /* check if element needs to be drawn grayed out, but also gray out * childs of a grayed out parent (pass on draw_grayed_out to childs) */ bool draw_childs_grayed_out = draw_grayed_out || (ten->flag & TE_DRAGGING); @@ -3223,7 +3220,7 @@ static void outliner_draw_tree_element(bContext *C, } } else { - for (TreeElement *ten = te->subtree.first; ten; ten = ten->next) { + LISTBASE_FOREACH (TreeElement *, ten, &te->subtree) { outliner_set_coord_tree_element(ten, startx, *starty); } @@ -3357,7 +3354,7 @@ static void outliner_draw_struct_marks(ARegion *region, ListBase *lb, int *starty) { - for (TreeElement *te = lb->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, lb) { TreeStoreElem *tselem = TREESTORE(te); /* selection status */ @@ -3406,7 +3403,7 @@ static void outliner_draw_highlights_recursive(uint pos, const bool is_searching = (SEARCHING_OUTLINER(soops) || (soops->outlinevis == SO_DATA_API && soops->search_string[0] != 0)); - for (TreeElement *te = lb->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, lb) { const TreeStoreElem *tselem = TREESTORE(te); const int start_y = *io_start_y; @@ -3555,7 +3552,7 @@ static void outliner_draw_tree(bContext *C, // items themselves starty = (int)region->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET; startx = 0; - for (TreeElement *te = soops->tree.first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, &soops->tree) { outliner_draw_tree_element(C, block, fstyle, diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c index e4e8e2a1542..60e6b423720 100644 --- a/source/blender/editors/space_outliner/outliner_edit.c +++ b/source/blender/editors/space_outliner/outliner_edit.c @@ -1292,7 +1292,7 @@ static void outliner_show_active(SpaceOutliner *so, ARegion *region, TreeElement return; } - for (TreeElement *ten = te->subtree.first; ten; ten = ten->next) { + LISTBASE_FOREACH (TreeElement *, ten, &te->subtree) { outliner_show_active(so, region, ten, id); } } @@ -1310,7 +1310,7 @@ static int outliner_show_active_exec(bContext *C, wmOperator *UNUSED(op)) ID *id = TREESTORE(active_element)->id; /* Expand all elements in the outliner with matching ID */ - for (TreeElement *te = so->tree.first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, &so->tree) { outliner_show_active(so, region, te, id); } diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c index d50a097e6f6..ec1595eb930 100644 --- a/source/blender/editors/space_outliner/outliner_select.c +++ b/source/blender/editors/space_outliner/outliner_select.c @@ -1252,7 +1252,7 @@ static bool do_outliner_range_select_recursive(ListBase *lb, TreeElement *cursor, bool selecting) { - for (TreeElement *te = lb->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, lb) { TreeStoreElem *tselem = TREESTORE(te); if (selecting) { @@ -1496,7 +1496,7 @@ static int outliner_box_select_exec(bContext *C, wmOperator *op) WM_operator_properties_border_to_rctf(op, &rectf); UI_view2d_region_to_view_rctf(®ion->v2d, &rectf, &rectf); - for (TreeElement *te = soops->tree.first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, &soops->tree) { outliner_item_box_select(soops, scene, &rectf, te, select); } diff --git a/source/blender/editors/space_outliner/outliner_sync.c b/source/blender/editors/space_outliner/outliner_sync.c index c08c7f54405..35dd91ff061 100644 --- a/source/blender/editors/space_outliner/outliner_sync.c +++ b/source/blender/editors/space_outliner/outliner_sync.c @@ -96,8 +96,8 @@ void ED_outliner_select_sync_flag_outliners(const bContext *C) wmWindowManager *wm = CTX_wm_manager(C); for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) { - for (ScrArea *area = screen->areabase.first; area; area = area->next) { - for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { if (sl->spacetype == SPACE_OUTLINER) { SpaceOutliner *soutliner = (SpaceOutliner *)sl; @@ -319,7 +319,7 @@ static void outliner_sync_selection_from_outliner(Scene *scene, SelectedItems *selected_items) { - for (TreeElement *te = tree->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, tree) { TreeStoreElem *tselem = TREESTORE(te); if (tselem->type == 0 && te->idcode == ID_OB) { @@ -500,7 +500,7 @@ static void outliner_sync_selection_to_outliner(ViewLayer *view_layer, SyncSelectActiveData *active_data, const SyncSelectTypes *sync_types) { - for (TreeElement *te = tree->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, tree) { TreeStoreElem *tselem = TREESTORE(te); if (tselem->type == 0 && te->idcode == ID_OB) { diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c index 730d0019f77..34ca2267b7a 100644 --- a/source/blender/editors/space_outliner/outliner_tools.c +++ b/source/blender/editors/space_outliner/outliner_tools.c @@ -518,7 +518,7 @@ static void merged_element_search_cb_recursive( char name[64]; int iconid; - for (TreeElement *te = tree->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, tree) { TreeStoreElem *tselem = TREESTORE(te); if (tree_element_id_type_to_index(te) == type && tselem_type == tselem->type) { diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c index d89a755f1c6..b226d291188 100644 --- a/source/blender/editors/space_outliner/outliner_tree.c +++ b/source/blender/editors/space_outliner/outliner_tree.c @@ -1254,7 +1254,7 @@ static bool outliner_library_id_show(Library *lib, ID *id, short filter_id_type) Collection *collection = (Collection *)id; bool has_non_scene_parent = false; - for (CollectionParent *cparent = collection->parents.first; cparent; cparent = cparent->next) { + LISTBASE_FOREACH (CollectionParent *, cparent, &collection->parents) { if (!(cparent->collection->flag & COLLECTION_IS_MASTER)) { has_non_scene_parent = true; } @@ -1387,7 +1387,7 @@ static void outliner_add_orphaned_datablocks(Main *mainvar, SpaceOutliner *soops static void outliner_add_layer_collection_objects( SpaceOutliner *soops, ListBase *tree, ViewLayer *layer, LayerCollection *lc, TreeElement *ten) { - for (CollectionObject *cob = lc->collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &lc->collection->gobject) { Base *base = BKE_view_layer_base_find(layer, cob->ob); TreeElement *te_object = outliner_add_element(soops, tree, base->object, ten, 0, 0); te_object->directdata = base; @@ -1405,7 +1405,7 @@ static void outliner_add_layer_collections_recursive(SpaceOutliner *soops, TreeElement *parent_ten, const bool show_objects) { - for (LayerCollection *lc = layer_collections->first; lc; lc = lc->next) { + LISTBASE_FOREACH (LayerCollection *, lc, layer_collections) { const bool exclude = (lc->flag & LAYER_COLLECTION_EXCLUDE) != 0; TreeElement *ten; @@ -1468,7 +1468,7 @@ BLI_INLINE void outliner_add_collection_objects(SpaceOutliner *soops, Collection *collection, TreeElement *parent) { - for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) { + LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) { outliner_add_element(soops, tree, cob->ob, parent, 0, 0); } } @@ -1479,7 +1479,7 @@ static TreeElement *outliner_add_collection_recursive(SpaceOutliner *soops, { outliner_add_collection_init(ten, collection); - for (CollectionChild *child = collection->children.first; child; child = child->next) { + LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { outliner_add_element(soops, &ten->subtree, &child->collection->id, ten, 0, 0); } @@ -1542,7 +1542,7 @@ static void outliner_make_object_parent_hierarchy_collections(SpaceOutliner *soo continue; } - for (LinkData *link = parent_ob_tree_elements->first; link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, parent_ob_tree_elements) { TreeElement *parent_ob_tree_element = link->data; TreeElement *parent_ob_collection_tree_element = NULL; bool found = false; @@ -1556,8 +1556,7 @@ static void outliner_make_object_parent_hierarchy_collections(SpaceOutliner *soo parent_ob_collection_tree_element = parent_ob_collection_tree_element->parent; } - for (LinkData *link_iter = child_ob_tree_elements->first; link_iter; - link_iter = link_iter->next) { + LISTBASE_FOREACH (LinkData *, link_iter, child_ob_tree_elements) { TreeElement *child_ob_tree_element = link_iter->data; if (child_ob_tree_element->parent == parent_ob_collection_tree_element) { @@ -1589,7 +1588,7 @@ static void outliner_make_object_parent_hierarchy_collections(SpaceOutliner *soo static void outliner_object_tree_elements_lookup_create_recursive(GHash *object_tree_elements_hash, TreeElement *te_parent) { - for (TreeElement *te = te_parent->subtree.first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, &te_parent->subtree) { TreeStoreElem *tselem = TREESTORE(te); if (tselem->type == TSE_LAYER_COLLECTION) { @@ -2427,7 +2426,7 @@ void outliner_build_tree( else if (soops->outlinevis == SO_VIEW_LAYER) { if (soops->filter & SO_FILTER_NO_COLLECTION) { /* Show objects in the view layer. */ - for (Base *base = view_layer->object_bases.first; base; base = base->next) { + LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { TreeElement *te_object = outliner_add_element( soops, &soops->tree, base->object, NULL, 0, 0); te_object->directdata = base; diff --git a/source/blender/editors/space_outliner/outliner_utils.c b/source/blender/editors/space_outliner/outliner_utils.c index 188a4e64897..a058c30cef2 100644 --- a/source/blender/editors/space_outliner/outliner_utils.c +++ b/source/blender/editors/space_outliner/outliner_utils.c @@ -78,7 +78,7 @@ TreeElement *outliner_find_item_at_y(const SpaceOutliner *soops, const ListBase *tree, float view_co_y) { - for (TreeElement *te_iter = tree->first; te_iter; te_iter = te_iter->next) { + LISTBASE_FOREACH (TreeElement *, te_iter, tree) { if (view_co_y < (te_iter->ys + UI_UNIT_Y)) { if (view_co_y >= te_iter->ys) { /* co_y is inside this element */ @@ -204,7 +204,7 @@ TreeElement *outliner_find_tse(SpaceOutliner *soops, const TreeStoreElem *tse) /* Find treestore that refers to given ID */ TreeElement *outliner_find_id(SpaceOutliner *soops, ListBase *lb, const ID *id) { - for (TreeElement *te = lb->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, lb) { TreeStoreElem *tselem = TREESTORE(te); if (tselem->type == 0) { if (tselem->id == id) { @@ -222,7 +222,7 @@ TreeElement *outliner_find_id(SpaceOutliner *soops, ListBase *lb, const ID *id) TreeElement *outliner_find_posechannel(ListBase *lb, const bPoseChannel *pchan) { - for (TreeElement *te = lb->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, lb) { if (te->directdata == pchan) { return te; } @@ -240,7 +240,7 @@ TreeElement *outliner_find_posechannel(ListBase *lb, const bPoseChannel *pchan) TreeElement *outliner_find_editbone(ListBase *lb, const EditBone *ebone) { - for (TreeElement *te = lb->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, lb) { if (te->directdata == ebone) { return te; } @@ -361,7 +361,7 @@ float outliner_restrict_columns_width(const SpaceOutliner *soops) /* Find first tree element in tree with matching treestore flag */ TreeElement *outliner_find_element_with_flag(const ListBase *lb, short flag) { - for (TreeElement *te = lb->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, lb) { if ((TREESTORE(te)->flag & flag) == flag) { return te; } |