[Bf-blender-cvs] [6feca523496] master: Outliner: Use general warning mechanics for library overrides

Julian Eisel noreply at git.blender.org
Wed May 25 20:16:34 CEST 2022


Commit: 6feca523496bd18111dfedf2fc2a29bda6d93612
Author: Julian Eisel
Date:   Wed May 25 19:29:39 2022 +0200
Branches: master
https://developer.blender.org/rB6feca523496bd18111dfedf2fc2a29bda6d93612

Outliner: Use general warning mechanics for library overrides

Library overrides were basically using their own system to display
warnings for tree elements, even though for other display elements we
have a more general solution. With the previous commit this has been
generalized further and made trivial to extend.

===================================================================

M	source/blender/editors/space_outliner/outliner_draw.cc
M	source/blender/editors/space_outliner/tree/tree_element.hh
M	source/blender/editors/space_outliner/tree/tree_element_overrides.cc
M	source/blender/editors/space_outliner/tree/tree_element_overrides.hh

===================================================================

diff --git a/source/blender/editors/space_outliner/outliner_draw.cc b/source/blender/editors/space_outliner/outliner_draw.cc
index daa1cbdccdb..3f47bda8e74 100644
--- a/source/blender/editors/space_outliner/outliner_draw.cc
+++ b/source/blender/editors/space_outliner/outliner_draw.cc
@@ -1921,91 +1921,6 @@ static void outliner_draw_overrides_restrictbuts(Main *bmain,
   }
 }
 
-static bool outliner_draw_overrides_warning_buts(uiBlock *block,
-                                                 ARegion *region,
-                                                 SpaceOutliner *space_outliner,
-                                                 ListBase *lb,
-                                                 const bool is_open)
-{
-  bool any_item_has_warnings = false;
-
-  LISTBASE_FOREACH (TreeElement *, te, lb) {
-    bool item_has_warnings = false;
-    const bool do_draw = outliner_is_element_in_view(te, &region->v2d);
-    int but_flag = UI_BUT_DRAG_LOCK;
-    const char *tip = nullptr;
-
-    TreeStoreElem *tselem = TREESTORE(te);
-    switch (tselem->type) {
-      case TSE_LIBRARY_OVERRIDE_BASE: {
-        ID *id = tselem->id;
-
-        if (id->flag & LIB_LIB_OVERRIDE_RESYNC_LEFTOVER) {
-          item_has_warnings = true;
-          if (do_draw) {
-            tip = TIP_(
-                "This override data-block is not needed anymore, but was detected as user-edited");
-          }
-        }
-        else if (ID_IS_OVERRIDE_LIBRARY_REAL(id) && ID_REAL_USERS(id) == 0) {
-          item_has_warnings = true;
-          if (do_draw) {
-            tip = TIP_("This override data-block is unused");
-          }
-        }
-        break;
-      }
-      case TSE_LIBRARY_OVERRIDE: {
-        TreeElementOverridesProperty &te_override_prop =
-            *tree_element_cast<TreeElementOverridesProperty>(te);
-        if (!te_override_prop.is_rna_path_valid) {
-          item_has_warnings = true;
-          if (do_draw) {
-            tip = TIP_(
-                "This override property does not exist in current data, it will be removed on "
-                "next .blend file save");
-          }
-        }
-        break;
-      }
-      default:
-        break;
-    }
-
-    const bool any_child_has_warnings = outliner_draw_overrides_warning_buts(
-        block,
-        region,
-        space_outliner,
-        &te->subtree,
-        is_open && TSELEM_OPEN(tselem, space_outliner));
-
-    if (do_draw &&
-        (item_has_warnings || (any_child_has_warnings && !TSELEM_OPEN(tselem, space_outliner)))) {
-      if (tip == nullptr) {
-        tip = TIP_("Some sub-items require attention");
-      }
-      uiBut *bt = uiDefIconBut(block,
-                               UI_BTYPE_BUT,
-                               1,
-                               ICON_ERROR,
-                               (int)(region->v2d.cur.xmax - OL_TOG_USER_BUTS_STATUS),
-                               te->ys,
-                               UI_UNIT_X,
-                               UI_UNIT_Y,
-                               nullptr,
-                               0.0,
-                               0.0,
-                               0.0,
-                               0.0,
-                               tip);
-      UI_but_flag_enable(bt, but_flag);
-    }
-    any_item_has_warnings = any_item_has_warnings || item_has_warnings || any_child_has_warnings;
-  }
-
-  return any_item_has_warnings;
-}
-
 static void outliner_draw_separator(ARegion *region, const int x)
 {
   View2D *v2d = &region->v2d;
@@ -3993,10 +3908,6 @@ void draw_outliner(const bContext *C)
     outliner_draw_userbuts(block, region, space_outliner, &space_outliner->tree);
   }
   else if (space_outliner->outlinevis == SO_OVERRIDES_LIBRARY) {
-    /* Draw overrides status columns. */
-    outliner_draw_overrides_warning_buts(
-        block, region, space_outliner, &space_outliner->tree, true);
-
     const int x = region->v2d.cur.xmax - right_column_width;
     outliner_draw_separator(region, x);
     if (space_outliner->lib_override_view_mode == SO_LIB_OVERRIDE_VIEW_PROPERTIES) {
diff --git a/source/blender/editors/space_outliner/tree/tree_element.hh b/source/blender/editors/space_outliner/tree/tree_element.hh
index d665ff49f53..0dcd75d340d 100644
--- a/source/blender/editors/space_outliner/tree/tree_element.hh
+++ b/source/blender/editors/space_outliner/tree/tree_element.hh
@@ -61,7 +61,7 @@ class AbstractTreeElement {
    * By letting this return a warning message, the tree element will display a warning icon with
    * the message in the tooltip.
    */
-  virtual blender::StringRefNull getWarning() const;
+  virtual StringRefNull getWarning() const;
 
   /**
    * Expand this tree element if it is displayed for the first time (as identified by its
diff --git a/source/blender/editors/space_outliner/tree/tree_element_overrides.cc b/source/blender/editors/space_outliner/tree/tree_element_overrides.cc
index 3a039da86c2..53e7b88c923 100644
--- a/source/blender/editors/space_outliner/tree/tree_element_overrides.cc
+++ b/source/blender/editors/space_outliner/tree/tree_element_overrides.cc
@@ -38,6 +38,19 @@ TreeElementOverridesBase::TreeElementOverridesBase(TreeElement &legacy_te, ID &i
   }
 }
 
+StringRefNull TreeElementOverridesBase::getWarning() const
+{
+  if (id.flag & LIB_LIB_OVERRIDE_RESYNC_LEFTOVER) {
+    return TIP_("This override data-block is not needed anymore, but was detected as user-edited");
+  }
+
+  if (ID_IS_OVERRIDE_LIBRARY_REAL(&id) && ID_REAL_USERS(&id) == 0) {
+    return TIP_("This override data-block is unused");
+  }
+
+  return {};
+}
+
 void TreeElementOverridesBase::expand(SpaceOutliner &space_outliner) const
 {
   BLI_assert(id.override_library != nullptr);
@@ -93,4 +106,15 @@ TreeElementOverridesProperty::TreeElementOverridesProperty(TreeElement &legacy_t
   legacy_te.name = override_data.override_property.rna_path;
 }
 
+StringRefNull TreeElementOverridesProperty::getWarning() const
+{
+  if (!is_rna_path_valid) {
+    return TIP_(
+        "This override property does not exist in current data, it will be removed on "
+        "next .blend file save");
+  }
+
+  return {};
+}
+
 }  // namespace blender::ed::outliner
diff --git a/source/blender/editors/space_outliner/tree/tree_element_overrides.hh b/source/blender/editors/space_outliner/tree/tree_element_overrides.hh
index b42e1c37a0f..1db46d9af1d 100644
--- a/source/blender/editors/space_outliner/tree/tree_element_overrides.hh
+++ b/source/blender/editors/space_outliner/tree/tree_element_overrides.hh
@@ -34,6 +34,8 @@ class TreeElementOverridesBase final : public AbstractTreeElement {
   TreeElementOverridesBase(TreeElement &legacy_te, ID &id);
 
   void expand(SpaceOutliner &) const override;
+
+  StringRefNull getWarning() const override;
 };
 
 class TreeElementOverridesProperty final : public AbstractTreeElement {
@@ -46,6 +48,8 @@ class TreeElementOverridesProperty final : public AbstractTreeElement {
 
  public:
   TreeElementOverridesProperty(TreeElement &legacy_te, TreeElementOverridesData &override_data);
+
+  StringRefNull getWarning() const override;
 };
 
 }  // namespace blender::ed::outliner



More information about the Bf-blender-cvs mailing list