[Bf-blender-cvs] [f1df685f570] master: Outliner: Refactor element warning and mode column querying

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


Commit: f1df685f570bbd248b0356fdb4afda1b181d6a09
Author: Julian Eisel
Date:   Wed May 25 12:53:07 2022 +0200
Branches: master
https://developer.blender.org/rBf1df685f570bbd248b0356fdb4afda1b181d6a09

Outliner: Refactor element warning and mode column querying

Uses a inheritance based approach for querying warning of tree elements
and the mode column support of display modes.

For the warnings, tree elements can override the
`AbstractTreeElement::getWarning()` method and return a warning string.
The UI will draw the warning column with warning icons. This makes the
warning column more generalized and easier to extend to more use-cases.
E.g. library override elements will use this after a followup commit.

To support mode toggles a display mode can now just return true in the
`AbstractTreeDisplay::supportsModeColumn()` method. This makes it
trivial to add mode columns to other display modes, and less error prone
because there's no need to hunt down a bunch of display mode checks in
different places.

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

M	source/blender/editors/space_outliner/CMakeLists.txt
M	source/blender/editors/space_outliner/outliner_draw.cc
M	source/blender/editors/space_outliner/outliner_intern.hh
A	source/blender/editors/space_outliner/outliner_query.cc
M	source/blender/editors/space_outliner/outliner_select.cc
M	source/blender/editors/space_outliner/outliner_tree.cc
M	source/blender/editors/space_outliner/tree/tree_display.cc
M	source/blender/editors/space_outliner/tree/tree_display.hh
M	source/blender/editors/space_outliner/tree/tree_display_libraries.cc
M	source/blender/editors/space_outliner/tree/tree_display_scenes.cc
M	source/blender/editors/space_outliner/tree/tree_display_view_layer.cc
M	source/blender/editors/space_outliner/tree/tree_element.cc
M	source/blender/editors/space_outliner/tree/tree_element.hh
M	source/blender/editors/space_outliner/tree/tree_element_id_library.cc
M	source/blender/editors/space_outliner/tree/tree_element_id_library.hh

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

diff --git a/source/blender/editors/space_outliner/CMakeLists.txt b/source/blender/editors/space_outliner/CMakeLists.txt
index 59f6bd85d59..1c09ad2d98f 100644
--- a/source/blender/editors/space_outliner/CMakeLists.txt
+++ b/source/blender/editors/space_outliner/CMakeLists.txt
@@ -27,6 +27,7 @@ set(SRC
   outliner_draw.cc
   outliner_edit.cc
   outliner_ops.cc
+  outliner_query.cc
   outliner_select.cc
   outliner_sync.cc
   outliner_tools.cc
diff --git a/source/blender/editors/space_outliner/outliner_draw.cc b/source/blender/editors/space_outliner/outliner_draw.cc
index d165e98d7d4..daa1cbdccdb 100644
--- a/source/blender/editors/space_outliner/outliner_draw.cc
+++ b/source/blender/editors/space_outliner/outliner_draw.cc
@@ -72,6 +72,7 @@
 #include "tree/tree_element_overrides.hh"
 #include "tree/tree_element_rna.hh"
 
+using namespace blender;
 using namespace blender::ed::outliner;
 
 /* -------------------------------------------------------------------- */
@@ -2285,19 +2286,19 @@ static void outliner_draw_mode_column(const bContext *C,
 static bool outliner_draw_warning_tree_element(uiBlock *block,
                                                SpaceOutliner *space_outliner,
                                                TreeElement *te,
-                                               TreeStoreElem *tselem,
                                                const bool use_mode_column,
                                                const int te_ys)
 {
-  if ((te->flag & TE_HAS_WARNING) == 0) {
-    /* If given element has no warning, recursively try to display the first sub-elements' warning.
+  const AbstractTreeElement *abstract_te = tree_element_cast<AbstractTreeElement>(te);
+  const StringRefNull warning_msg = abstract_te ? abstract_te->getWarning() : "";
+
+  if (warning_msg.is_empty()) {
+    /* If given element has no warning, recursively try to display the first sub-element's warning.
      */
-    if (!TSELEM_OPEN(tselem, space_outliner)) {
+    if (!TSELEM_OPEN(te->store_elem, space_outliner)) {
       LISTBASE_FOREACH (TreeElement *, sub_te, &te->subtree) {
-        TreeStoreElem *sub_tselem = TREESTORE(sub_te);
-
         if (outliner_draw_warning_tree_element(
-                block, space_outliner, sub_te, sub_tselem, use_mode_column, te_ys)) {
+                block, space_outliner, sub_te, use_mode_column, te_ys)) {
           return true;
         }
       }
@@ -2305,12 +2306,6 @@ static bool outliner_draw_warning_tree_element(uiBlock *block,
     return false;
   }
 
-  int icon = ICON_NONE;
-  const char *tip = "";
-  const bool has_warning = tree_element_warnings_get(te, &icon, &tip);
-  BLI_assert(has_warning);
-  UNUSED_VARS_NDEBUG(has_warning);
-
   /* Move the warnings a unit left in view layer mode. */
   const short mode_column_offset = (use_mode_column && (space_outliner->outlinevis == SO_SCENES)) ?
                                        UI_UNIT_X :
@@ -2320,7 +2315,7 @@ static bool outliner_draw_warning_tree_element(uiBlock *block,
   uiBut *but = uiDefIconBut(block,
                             UI_BTYPE_ICON_TOGGLE,
                             0,
-                            icon,
+                            ICON_ERROR,
                             mode_column_offset,
                             te_ys,
                             UI_UNIT_X,
@@ -2330,7 +2325,7 @@ static bool outliner_draw_warning_tree_element(uiBlock *block,
                             0.0,
                             0.0,
                             0.0,
-                            tip);
+                            warning_msg.c_str());
   /* No need for undo here, this is a pure info widget. */
   UI_but_flag_disable(but, UI_BUT_UNDO);
 
@@ -2344,11 +2339,9 @@ static void outliner_draw_warning_column(const bContext *C,
                                          ListBase *tree)
 {
   LISTBASE_FOREACH (TreeElement *, te, tree) {
-    TreeStoreElem *tselem = TREESTORE(te);
-
-    outliner_draw_warning_tree_element(block, space_outliner, te, tselem, use_mode_column, te->ys);
+    outliner_draw_warning_tree_element(block, space_outliner, te, use_mode_column, te->ys);
 
-    if (TSELEM_OPEN(tselem, space_outliner)) {
+    if (TSELEM_OPEN(te->store_elem, space_outliner)) {
       outliner_draw_warning_column(C, block, space_outliner, use_mode_column, &te->subtree);
     }
   }
@@ -3961,13 +3954,8 @@ void draw_outliner(const bContext *C)
   UI_view2d_view_ortho(v2d);
 
   /* Only show mode column in View Layers and Scenes view. */
-  const bool use_mode_column = (space_outliner->flag & SO_MODE_COLUMN) &&
-                               (ELEM(space_outliner->outlinevis, SO_VIEW_LAYER, SO_SCENES));
-
-  const bool use_warning_column = ELEM(space_outliner->outlinevis,
-                                       SO_LIBRARIES,
-                                       SO_OVERRIDES_LIBRARY) &&
-                                  space_outliner->runtime->tree_display->hasWarnings();
+  const bool use_mode_column = outliner_shows_mode_column(*space_outliner);
+  const bool use_warning_column = outliner_has_element_warnings(*space_outliner);
 
   /* Draw outliner stuff (background, hierarchy lines and names). */
   const float right_column_width = outliner_right_columns_width(space_outliner);
diff --git a/source/blender/editors/space_outliner/outliner_intern.hh b/source/blender/editors/space_outliner/outliner_intern.hh
index f3bcb7b0f1e..190b8f2fe36 100644
--- a/source/blender/editors/space_outliner/outliner_intern.hh
+++ b/source/blender/editors/space_outliner/outliner_intern.hh
@@ -160,8 +160,6 @@ enum {
   /* Child elements of the same type in the icon-row are drawn merged as one icon.
    * This flag is set for an element that is part of these merged child icons. */
   TE_ICONROW_MERGED = (1 << 7),
-  /* This element has some warning to be displayed. */
-  TE_HAS_WARNING = (1 << 8),
 };
 
 /* button events */
@@ -510,6 +508,11 @@ void OUTLINER_OT_drivers_delete_selected(struct wmOperatorType *ot);
 
 void OUTLINER_OT_orphans_purge(struct wmOperatorType *ot);
 
+/* outliner_query.cc ---------------------------------------------- */
+
+bool outliner_shows_mode_column(const SpaceOutliner &space_outliner);
+bool outliner_has_element_warnings(const SpaceOutliner &space_outliner);
+
 /* outliner_tools.c ---------------------------------------------- */
 
 void merged_element_search_menu_invoke(struct bContext *C,
diff --git a/source/blender/editors/space_outliner/outliner_query.cc b/source/blender/editors/space_outliner/outliner_query.cc
new file mode 100644
index 00000000000..d6483c44fce
--- /dev/null
+++ b/source/blender/editors/space_outliner/outliner_query.cc
@@ -0,0 +1,48 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup spoutliner
+ */
+
+#include <functional>
+
+#include "BLI_listbase.h"
+
+#include "DNA_space_types.h"
+
+#include "outliner_intern.hh"
+#include "tree/tree_display.hh"
+
+using namespace blender::ed::outliner;
+
+bool outliner_shows_mode_column(const SpaceOutliner &space_outliner)
+{
+  const AbstractTreeDisplay &tree_display = *space_outliner.runtime->tree_display;
+
+  return tree_display.supportsModeColumn() && (space_outliner.flag & SO_MODE_COLUMN);
+}
+
+/**
+ * Iterate over the entire tree (including collapsed sub-elements), probing if any of the elements
+ * has a warning to be displayed.
+ */
+bool outliner_has_element_warnings(const SpaceOutliner &space_outliner)
+{
+  std::function<bool(const ListBase &)> recursive_fn;
+
+  recursive_fn = [&](const ListBase &lb) {
+    LISTBASE_FOREACH (const TreeElement *, te, &lb) {
+      if (te->abstract_element && !te->abstract_element->getWarning().is_empty()) {
+        return true;
+      }
+
+      if (recursive_fn(te->subtree)) {
+        return true;
+      }
+    }
+
+    return false;
+  };
+
+  return recursive_fn(space_outliner.tree);
+}
diff --git a/source/blender/editors/space_outliner/outliner_select.cc b/source/blender/editors/space_outliner/outliner_select.cc
index fd0ee422df0..f7c65bfcff2 100644
--- a/source/blender/editors/space_outliner/outliner_select.cc
+++ b/source/blender/editors/space_outliner/outliner_select.cc
@@ -66,6 +66,7 @@
 #include "RNA_prototypes.h"
 
 #include "outliner_intern.hh"
+#include "tree/tree_display.hh"
 #include "tree/tree_element_seq.hh"
 
 using namespace blender::ed::outliner;
@@ -1557,12 +1558,11 @@ static bool outliner_is_co_within_restrict_columns(const SpaceOutliner *space_ou
 
 bool outliner_is_co_within_mode_column(SpaceOutliner *space_outliner, const float view_mval[2])
 {
-  /* Mode toggles only show in View Layer and Scenes modes. */
-  if (!ELEM(space_outliner->outlinevis, SO_VIEW_LAYER, SO_SCENES)) {
+  if (!outliner_shows_mode_column(*space_outliner)) {
     return false;
   }
 
-  return space_outliner->flag & SO_MODE_COLUMN && view_mval[0] < UI_UNIT_X;
+  return view_mval[0] < UI_UNIT_X;
 }
 
 static bool outliner_is_co_within_active_mode_column(bContext *C,
diff --git a/source/blender/editors/space_outliner/outliner_tree.cc b/source/blender/editors/space_outliner/outliner_tree.cc
index bbd9b48c260..7b3ce499929 100644
--- a/source/blender/editors/space_outliner/outliner_tree.cc
+++ b/source/blender/editors/space_outliner/outliner_tree.cc
@@ -919,10 +919,6 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
     BLI_assert_msg(false, "Element type should already use new AbstractTreeElement design");
   }
 
-  if (tree_element_warnings_get(te, nullptr, nullptr)) {
-    te->flag |= TE_HAS_WARNING;
-  }
-
   return te;
 }
 
diff --git a/source/blender/editors/space_outliner/tree/tree_display.cc b/source/blender/editors/space_outliner/tree/tree_display.cc
index 141c68594e8..6ab497b3fbb 100644
--- a/source/blender/editors/space_outliner/tree/tree_display.cc
+++ b/source/blender/editors/space_outliner/tree/tree_display.cc
@@ -45,9 +45,9 @@ std::unique_ptr<AbstractTreeDisplay> AbstractTreeDisplay::createFromDisplayMode(
   return nullptr;
 }
 
-bool AbstractTreeDisplay::hasWarnings() const
+bool AbstractTreeDisplay::supportsModeColumn() const
 {
-  return has_warnings;
+  return false;
 }
 
 }  // namespace blender::ed::outliner
diff --git a/source/blender/editors/space_outliner/tree/tree_display

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list