Page MenuHome

Cleanup: Disentangle outliner active status "get" and "set"
ClosedPublic

Authored by Hans Goudey (HooglyBoogly) on Jan 28 2021, 4:51 AM.

Details

Summary

Previously the same functions were used to both set and get the active
state for outliner tree elements. This has quite a few problems.

  • It's hard to tell when data is changed or simply read
  • It prevents using const
  • The code is full of if statements, making it longer and less readable.

This replaces the tree_element_type_active and tree_element_active
functions with _get and _set variants. One has const arguments and
returns the active state, the other deals only with setting the state.
While this refactor results in slightly more lines of code, the result
is much better in my opinion.

This commit also removes unused variables from arguments of the affected
functions.

I don't expect a full review of this, just a big picture yay or nay.
Note that there are a few places where it was necessary to cast away
const (in outliner_search_back and BKE_view_layer_base_find.
I think that's a fine trade-off. "const" variants of the two functions
could be created, but I don't think that's worth it.

Diff Detail

Repository
rB Blender
Branch
cleanup-outliner-active-draw (branched from master)
Build Status
Buildable 12433
Build 12433: arc lint + arc unit

Event Timeline

Hans Goudey (HooglyBoogly) requested review of this revision.Jan 28 2021, 4:51 AM
Hans Goudey (HooglyBoogly) created this revision.
  • Move a few remaining types to switch statements, correct comment

While this refactor results in slightly more lines of code, the result is much better in my opinion.

I agree. This looks fine to me

One question that this raises is why the get active state logic is in outliner_select.c. I don't think it should be part of this patch, but maybe later cleanups related to the tree_element_*.cc files could move that logic somewhere else.

This revision is now accepted and ready to land.Feb 18 2021, 7:54 PM
  • Merge branch 'master' into cleanup-outliner-active-draw

Generally looks fine.

I'd suggest to change the function naming though.

  • _active_set(): This isn't a mere setter, changing the active data may cause a number of changes. Maybe _activate() emphasizes this better?
  • _active_get(): Reads like this gives you the active item. Could be _state_get() or _drawstate_get()? (Not sure I like the term "draw-state" that much though).

Good point, I like the naming you suggested much more. Another benefit is avoiding the confusion from the "set" and "get" function names only differing by a single letter.

  • Merge branch 'master' into cleanup-outliner-active-draw
  • Rename three more functions