From 23363ca08498b4c9d05321186f608f71b8489406 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 29 Sep 2020 17:08:32 -0500 Subject: Cleanup: Use LISTBASE_FOREACH macro in outliner code --- .../editors/space_outliner/outliner_dragdrop.c | 8 +- .../blender/editors/space_outliner/outliner_edit.c | 105 +++++++-------------- .../editors/space_outliner/outliner_select.c | 4 +- .../editors/space_outliner/outliner_tools.c | 33 ++----- .../blender/editors/space_outliner/outliner_tree.c | 8 +- .../editors/space_outliner/outliner_utils.c | 8 +- 6 files changed, 57 insertions(+), 109 deletions(-) (limited to 'source') diff --git a/source/blender/editors/space_outliner/outliner_dragdrop.c b/source/blender/editors/space_outliner/outliner_dragdrop.c index 302d606e4c8..cbe6887f66e 100644 --- a/source/blender/editors/space_outliner/outliner_dragdrop.c +++ b/source/blender/editors/space_outliner/outliner_dragdrop.c @@ -85,8 +85,8 @@ static TreeElement *outliner_dropzone_element(TreeElement *te, } /* Not it. Let's look at its children. */ if (children && (TREESTORE(te)->flag & TSE_CLOSED) == 0 && (te->subtree.first)) { - for (te = te->subtree.first; te; te = te->next) { - TreeElement *te_valid = outliner_dropzone_element(te, fmval, children); + LISTBASE_FOREACH (TreeElement *, te_sub, &te->subtree) { + TreeElement *te_valid = outliner_dropzone_element(te_sub, fmval, children); if (te_valid) { return te_valid; } @@ -100,9 +100,7 @@ static TreeElement *outliner_dropzone_find(const SpaceOutliner *space_outliner, const float fmval[2], const bool children) { - TreeElement *te; - - for (te = space_outliner->tree.first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, &space_outliner->tree) { TreeElement *te_valid = outliner_dropzone_element(te, fmval, children); if (te_valid) { return te_valid; diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c index dea67a8678d..87c0819a667 100644 --- a/source/blender/editors/space_outliner/outliner_edit.c +++ b/source/blender/editors/space_outliner/outliner_edit.c @@ -377,8 +377,8 @@ static void do_outliner_item_rename(ReportList *reports, } } - for (te = te->subtree.first; te; te = te->next) { - do_outliner_item_rename(reports, region, te, mval); + LISTBASE_FOREACH (TreeElement *, te_child, &te->subtree) { + do_outliner_item_rename(reports, region, te_child, mval); } } @@ -386,7 +386,6 @@ static int outliner_item_rename(bContext *C, wmOperator *op, const wmEvent *even { ARegion *region = CTX_wm_region(C); SpaceOutliner *space_outliner = CTX_wm_space_outliner(C); - TreeElement *te; float fmval[2]; /* Rename active element if key pressed, otherwise rename element at cursor coordinates */ @@ -404,7 +403,7 @@ static int outliner_item_rename(bContext *C, wmOperator *op, const wmEvent *even else { UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]); - for (te = space_outliner->tree.first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, &space_outliner->tree) { do_outliner_item_rename(op->reports, region, te, fmval); } } @@ -502,9 +501,9 @@ static int outliner_id_delete_invoke_do(bContext *C, } } else { - for (te = te->subtree.first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te_sub, &te->subtree) { int ret; - if ((ret = outliner_id_delete_invoke_do(C, reports, te, mval))) { + if ((ret = outliner_id_delete_invoke_do(C, reports, te_sub, mval))) { return ret; } } @@ -517,14 +516,13 @@ static int outliner_id_delete_invoke(bContext *C, wmOperator *op, const wmEvent { ARegion *region = CTX_wm_region(C); SpaceOutliner *space_outliner = CTX_wm_space_outliner(C); - TreeElement *te; float fmval[2]; BLI_assert(region && space_outliner); UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]); - for (te = space_outliner->tree.first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, &space_outliner->tree) { int ret; if ((ret = outliner_id_delete_invoke_do(C, op->reports, te, fmval))) { @@ -609,9 +607,7 @@ static bool outliner_id_remap_find_tree_element(bContext *C, ListBase *tree, const float y) { - TreeElement *te; - - for (te = tree->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, tree) { if (y > te->ys && y < te->ys + UI_UNIT_Y) { TreeStoreElem *tselem = TREESTORE(te); @@ -734,12 +730,10 @@ void id_remap_fn(bContext *C, static int outliner_id_copy_tag(SpaceOutliner *space_outliner, ListBase *tree) { - TreeElement *te; - TreeStoreElem *tselem; int num_ids = 0; - for (te = tree->first; te; te = te->next) { - tselem = TREESTORE(te); + LISTBASE_FOREACH (TreeElement *, te, tree) { + TreeStoreElem *tselem = TREESTORE(te); /* if item is selected and is an ID, tag it as needing to be copied. */ if (tselem->flag & TSE_SELECTED && ELEM(tselem->type, 0, TSE_LAYER_COLLECTION)) { @@ -903,9 +897,9 @@ static int outliner_lib_relocate_invoke_do( } } else { - for (te = te->subtree.first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te_sub, &te->subtree) { int ret; - if ((ret = outliner_lib_relocate_invoke_do(C, reports, te, mval, reload))) { + if ((ret = outliner_lib_relocate_invoke_do(C, reports, te_sub, mval, reload))) { return ret; } } @@ -918,14 +912,13 @@ static int outliner_lib_relocate_invoke(bContext *C, wmOperator *op, const wmEve { ARegion *region = CTX_wm_region(C); SpaceOutliner *space_outliner = CTX_wm_space_outliner(C); - TreeElement *te; float fmval[2]; BLI_assert(region && space_outliner); UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]); - for (te = space_outliner->tree.first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, &space_outliner->tree) { int ret; if ((ret = outliner_lib_relocate_invoke_do(C, op->reports, te, fmval, false))) { @@ -969,14 +962,13 @@ static int outliner_lib_reload_invoke(bContext *C, wmOperator *op, const wmEvent { ARegion *region = CTX_wm_region(C); SpaceOutliner *space_outliner = CTX_wm_space_outliner(C); - TreeElement *te; float fmval[2]; BLI_assert(region && space_outliner); UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]); - for (te = space_outliner->tree.first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, &space_outliner->tree) { int ret; if ((ret = outliner_lib_relocate_invoke_do(C, op->reports, te, fmval, true))) { @@ -1027,12 +1019,10 @@ void lib_reload_fn(bContext *C, static int outliner_count_levels(ListBase *lb, const int curlevel) { - TreeElement *te; - int level = curlevel, lev; + int level = curlevel; - for (te = lb->first; te; te = te->next) { - - lev = outliner_count_levels(&te->subtree, curlevel + 1); + LISTBASE_FOREACH (TreeElement *, te, lb) { + int lev = outliner_count_levels(&te->subtree, curlevel + 1); if (lev > level) { level = lev; } @@ -1042,17 +1032,13 @@ static int outliner_count_levels(ListBase *lb, const int curlevel) int outliner_flag_is_any_test(ListBase *lb, short flag, const int curlevel) { - TreeElement *te; - TreeStoreElem *tselem; - int level; - - for (te = lb->first; te; te = te->next) { - tselem = TREESTORE(te); + LISTBASE_FOREACH (TreeElement *, te, lb) { + TreeStoreElem *tselem = TREESTORE(te); if (tselem->flag & flag) { return curlevel; } - level = outliner_flag_is_any_test(&te->subtree, flag, curlevel + 1); + int level = outliner_flag_is_any_test(&te->subtree, flag, curlevel + 1); if (level) { return level; } @@ -1066,14 +1052,11 @@ int outliner_flag_is_any_test(ListBase *lb, short flag, const int curlevel) */ bool outliner_flag_set(ListBase *lb, short flag, short set) { - TreeElement *te; - TreeStoreElem *tselem; bool changed = false; - bool has_flag; - for (te = lb->first; te; te = te->next) { - tselem = TREESTORE(te); - has_flag = (tselem->flag & flag); + LISTBASE_FOREACH (TreeElement *, te, lb) { + TreeStoreElem *tselem = TREESTORE(te); + bool has_flag = (tselem->flag & flag); if (set == 0) { if (has_flag) { tselem->flag &= ~flag; @@ -1092,12 +1075,10 @@ bool outliner_flag_set(ListBase *lb, short flag, short set) bool outliner_flag_flip(ListBase *lb, short flag) { - TreeElement *te; - TreeStoreElem *tselem; bool changed = false; - for (te = lb->first; te; te = te->next) { - tselem = TREESTORE(te); + LISTBASE_FOREACH (TreeElement *, te, lb) { + TreeStoreElem *tselem = TREESTORE(te); tselem->flag ^= flag; changed |= outliner_flag_flip(&te->subtree, flag); } @@ -1256,10 +1237,9 @@ static void outliner_set_coordinates_element_recursive(SpaceOutliner *space_outl /* to retrieve coordinates with redrawing the entire tree */ void outliner_set_coordinates(ARegion *region, SpaceOutliner *space_outliner) { - TreeElement *te; int starty = (int)(region->v2d.tot.ymax) - UI_UNIT_Y; - for (te = space_outliner->tree.first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, &space_outliner->tree) { outliner_set_coordinates_element_recursive(space_outliner, te, 0, &starty); } } @@ -1558,11 +1538,8 @@ static void outliner_find_panel( /* helper function for Show/Hide one level operator */ static void outliner_openclose_level(ListBase *lb, int curlevel, int level, int open) { - TreeElement *te; - TreeStoreElem *tselem; - - for (te = lb->first; te; te = te->next) { - tselem = TREESTORE(te); + LISTBASE_FOREACH (TreeElement *, te, lb) { + TreeStoreElem *tselem = TREESTORE(te); if (open) { if (curlevel <= level) { @@ -1636,11 +1613,8 @@ void OUTLINER_OT_show_one_level(wmOperatorType *ot) * recursively checks whether subtrees have any objects. */ static int subtree_has_objects(ListBase *lb) { - TreeElement *te; - TreeStoreElem *tselem; - - for (te = lb->first; te; te = te->next) { - tselem = TREESTORE(te); + LISTBASE_FOREACH (TreeElement *, te, lb) { + TreeStoreElem *tselem = TREESTORE(te); if (tselem->type == 0 && te->idcode == ID_OB) { return 1; } @@ -1654,12 +1628,9 @@ static int subtree_has_objects(ListBase *lb) /* recursive helper function for Show Hierarchy operator */ static void tree_element_show_hierarchy(Scene *scene, SpaceOutliner *space_outliner, ListBase *lb) { - TreeElement *te; - TreeStoreElem *tselem; - /* open all object elems, close others */ - for (te = lb->first; te; te = te->next) { - tselem = TREESTORE(te); + LISTBASE_FOREACH (TreeElement *, te, lb) { + TreeStoreElem *tselem = TREESTORE(te); if (ELEM(tselem->type, 0, @@ -1915,11 +1886,8 @@ static void do_outliner_drivers_editop(SpaceOutliner *space_outliner, ReportList *reports, short mode) { - TreeElement *te; - TreeStoreElem *tselem; - - for (te = tree->first; te; te = te->next) { - tselem = TREESTORE(te); + LISTBASE_FOREACH (TreeElement *, te, tree) { + TreeStoreElem *tselem = TREESTORE(te); /* if item is selected, perform operation */ if (tselem->flag & TSE_SELECTED) { @@ -2113,11 +2081,8 @@ static void do_outliner_keyingset_editop(SpaceOutliner *space_outliner, ListBase *tree, short mode) { - TreeElement *te; - TreeStoreElem *tselem; - - for (te = tree->first; te; te = te->next) { - tselem = TREESTORE(te); + LISTBASE_FOREACH (TreeElement *, te, tree) { + TreeStoreElem *tselem = TREESTORE(te); /* if item is selected, perform operation */ if (tselem->flag & TSE_SELECTED) { diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c index 602bb351c0f..8034996f5c3 100644 --- a/source/blender/editors/space_outliner/outliner_select.c +++ b/source/blender/editors/space_outliner/outliner_select.c @@ -1419,8 +1419,8 @@ static void outliner_item_box_select(bContext *C, /* Look at its children. */ if (TSELEM_OPEN(tselem, space_outliner)) { - for (te = te->subtree.first; te; te = te->next) { - outliner_item_box_select(C, space_outliner, scene, rectf, te, select); + LISTBASE_FOREACH (TreeElement *, te_sub, &te->subtree) { + outliner_item_box_select(C, space_outliner, scene, rectf, te_sub, select); } } } diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c index a4043d426a3..d51af47aed5 100644 --- a/source/blender/editors/space_outliner/outliner_tools.c +++ b/source/blender/editors/space_outliner/outliner_tools.c @@ -394,11 +394,8 @@ static void outliner_do_libdata_operation(bContext *C, outliner_operation_fn operation_fn, void *user_data) { - TreeElement *te; - TreeStoreElem *tselem; - - for (te = lb->first; te; te = te->next) { - tselem = TREESTORE(te); + LISTBASE_FOREACH (TreeElement *, te, lb) { + TreeStoreElem *tselem = TREESTORE(te); if (tselem->flag & TSE_SELECTED) { if ((tselem->type == 0 && te->idcode != 0) || tselem->type == TSE_LAYER_COLLECTION) { TreeStoreElem *tsep = te->parent ? TREESTORE(te->parent) : NULL; @@ -433,12 +430,10 @@ static bool outliner_do_scene_operation( ListBase *lb, bool (*operation_fn)(bContext *, eOutliner_PropSceneOps, TreeElement *, TreeStoreElem *)) { - TreeElement *te; - TreeStoreElem *tselem; bool success = false; - for (te = lb->first; te; te = te->next) { - tselem = TREESTORE(te); + LISTBASE_FOREACH (TreeElement *, te, lb) { + TreeStoreElem *tselem = TREESTORE(te); if (tselem->flag & TSE_SELECTED) { if (operation_fn(C, event, te, tselem)) { success = true; @@ -1013,8 +1008,7 @@ void outliner_do_object_operation_ex(bContext *C, void *user_data, bool recurse_selected) { - TreeElement *te; - for (te = lb->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, lb) { TreeStoreElem *tselem = TREESTORE(te); bool select_handled = false; if (tselem->flag & TSE_SELECTED) { @@ -1101,11 +1095,10 @@ static void refreshdrivers_animdata_fn(int UNUSED(event), void *UNUSED(arg)) { IdAdtTemplate *iat = (IdAdtTemplate *)tselem->id; - FCurve *fcu; /* Loop over drivers, performing refresh * (i.e. check graph_buttons.c and rna_fcurve.c for details). */ - for (fcu = iat->adt->drivers.first; fcu; fcu = fcu->next) { + LISTBASE_FOREACH (FCurve *, fcu, &iat->adt->drivers) { fcu->flag &= ~FCURVE_DISABLED; if (fcu->driver) { @@ -1320,11 +1313,8 @@ static void outliner_do_data_operation( void (*operation_fn)(int, TreeElement *, TreeStoreElem *, void *), void *arg) { - TreeElement *te; - TreeStoreElem *tselem; - - for (te = lb->first; te; te = te->next) { - tselem = TREESTORE(te); + LISTBASE_FOREACH (TreeElement *, te, lb) { + TreeStoreElem *tselem = TREESTORE(te); if (tselem->flag & TSE_SELECTED) { if (tselem->type == type) { operation_fn(event, te, tselem, arg); @@ -2258,11 +2248,8 @@ static void outliner_do_id_set_operation( ID *newid, void (*operation_fn)(TreeElement *, TreeStoreElem *, TreeStoreElem *, ID *)) { - TreeElement *te; - TreeStoreElem *tselem; - - for (te = lb->first; te; te = te->next) { - tselem = TREESTORE(te); + LISTBASE_FOREACH (TreeElement *, te, lb) { + TreeStoreElem *tselem = TREESTORE(te); if (tselem->flag & TSE_SELECTED) { if (tselem->type == type) { TreeStoreElem *tsep = te->parent ? TREESTORE(te->parent) : NULL; diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c index 22a7019ab91..67be889b140 100644 --- a/source/blender/editors/space_outliner/outliner_tree.c +++ b/source/blender/editors/space_outliner/outliner_tree.c @@ -1957,8 +1957,8 @@ static void outliner_sort(ListBase *lb) } } - for (te = lb->first; te; te = te->next) { - outliner_sort(&te->subtree); + LISTBASE_FOREACH (TreeElement *, te_iter, lb) { + outliner_sort(&te_iter->subtree); } } @@ -2001,8 +2001,8 @@ static void outliner_collections_children_sort(ListBase *lb) } } - for (te = lb->first; te; te = te->next) { - outliner_collections_children_sort(&te->subtree); + LISTBASE_FOREACH (TreeElement *, te_iter, lb) { + outliner_collections_children_sort(&te_iter->subtree); } } diff --git a/source/blender/editors/space_outliner/outliner_utils.c b/source/blender/editors/space_outliner/outliner_utils.c index 8ec1db9a928..c0772e6001a 100644 --- a/source/blender/editors/space_outliner/outliner_utils.c +++ b/source/blender/editors/space_outliner/outliner_utils.c @@ -165,12 +165,11 @@ TreeElement *outliner_find_item_at_x_in_row(const SpaceOutliner *space_outliner, /* Find specific item from the treestore */ TreeElement *outliner_find_tree_element(ListBase *lb, const TreeStoreElem *store_elem) { - TreeElement *te, *tes; - for (te = lb->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, lb) { if (te->store_elem == store_elem) { return te; } - tes = outliner_find_tree_element(&te->subtree, store_elem); + TreeElement *tes = outliner_find_tree_element(&te->subtree, store_elem); if (tes) { return tes; } @@ -183,8 +182,7 @@ TreeElement *outliner_find_parent_element(ListBase *lb, TreeElement *parent_te, const TreeElement *child_te) { - TreeElement *te; - for (te = lb->first; te; te = te->next) { + LISTBASE_FOREACH (TreeElement *, te, lb) { if (te == child_te) { return parent_te; } -- cgit v1.2.3