diff options
author | Hans Goudey <h.goudey@me.com> | 2021-06-16 05:10:30 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-06-16 05:10:30 +0300 |
commit | f5dee9b7a5cb164cf6fee92ad0912f03f06df443 (patch) | |
tree | 42bb2b8818097d88b86cb358274bfee52140ccc4 | |
parent | f5f58882ef34d6edc671233c3ac64848079e35a9 (diff) |
Split selection filter and row filters (filter flag no longer applies to selection filter)
5 files changed, 57 insertions, 28 deletions
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_data_source.hh b/source/blender/editors/space_spreadsheet/spreadsheet_data_source.hh index de47109a144..fad1770e621 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_data_source.hh +++ b/source/blender/editors/space_spreadsheet/spreadsheet_data_source.hh @@ -54,6 +54,15 @@ class DataSource { } /** + * Returns true iff the data source has the ability to limit visible rows + * by user interface selection status. + */ + virtual bool has_selection_filter() const + { + return false; + } + + /** * Returns the number of rows in columns returned by #get_column_values. */ virtual int tot_rows() const diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc b/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc index 8857dce3f81..7d36d4b1b7f 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc @@ -226,6 +226,17 @@ static void get_selected_indices_on_domain(const Mesh &mesh, } } +bool GeometryDataSource::has_selection_filter() const +{ + Object *object_orig = DEG_get_original_object(object_eval_); + if (object_orig->type == OB_MESH) { + if (object_orig->mode == OB_MODE_EDIT) { + return true; + } + } + return false; +} + void GeometryDataSource::apply_selection_filter(MutableSpan<bool> rows_included) const { std::lock_guard lock{mutex_}; @@ -265,6 +276,11 @@ void GeometryDataSource::apply_selection_filter(MutableSpan<bool> rows_included) } } +bool InstancesDataSource::has_selection_filter() const +{ + return false; +} + void InstancesDataSource::foreach_default_column_ids( FunctionRef<void(const SpreadsheetColumnID &)> fn) const { diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.hh b/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.hh index d5dd8de0146..d1b5dc6845e 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.hh +++ b/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.hh @@ -58,6 +58,7 @@ class GeometryDataSource : public DataSource { return object_eval_; } + bool has_selection_filter() const override; void apply_selection_filter(MutableSpan<bool> rows_included) const; void foreach_default_column_ids( diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc index 87e3bd02ec6..a3c23581446 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc @@ -265,29 +265,36 @@ static void apply_row_filter(const SpreadsheetLayout &spreadsheet_layout, } } -bool spreadsheet_data_source_has_selection_filter(const DataSource &data_source) +static void index_vector_from_bools(Span<bool> selection, Vector<int64_t> &indices) { - if (const GeometryDataSource *geometry_data_source = dynamic_cast<const GeometryDataSource *>( - &data_source)) { - Object *object_eval = geometry_data_source->object_eval(); - Object *object_orig = DEG_get_original_object(object_eval); - if (object_orig->type == OB_MESH) { - if (object_orig->mode == OB_MODE_EDIT) { - return true; - } + for (const int i : selection.index_range()) { + if (selection[i]) { + indices.append(i); } } +} - return false; +static bool use_row_filters(const SpaceSpreadsheet &sspreadsheet) +{ + if (!(sspreadsheet.filter_flag & SPREADSHEET_FILTER_ENABLE)) { + return false; + } + if (BLI_listbase_is_empty(&sspreadsheet.row_filters)) { + return false; + } + return true; } -static void index_vector_from_bools(Span<bool> selection, Vector<int64_t> &indices) +static bool use_selection_filter(const SpaceSpreadsheet &sspreadsheet, + const DataSource &data_source) { - for (const int i : selection.index_range()) { - if (selection[i]) { - indices.append(i); - } + if (!(sspreadsheet.filter_flag & SPREADSHEET_FILTER_SELECTED_ONLY)) { + return false; + } + if (!data_source.has_selection_filter()) { + return false; } + return true; } Span<int64_t> spreadsheet_filter_rows(const SpaceSpreadsheet &sspreadsheet, @@ -297,29 +304,27 @@ Span<int64_t> spreadsheet_filter_rows(const SpaceSpreadsheet &sspreadsheet, { const int tot_rows = data_source.tot_rows(); - if (!(sspreadsheet.filter_flag & SPREADSHEET_FILTER_ENABLE)) { - return IndexRange(tot_rows).as_span(); - } - - const bool use_selection = (sspreadsheet.filter_flag & SPREADSHEET_FILTER_SELECTED_ONLY) && - spreadsheet_data_source_has_selection_filter(data_source); + const bool use_selection = use_selection_filter(sspreadsheet, data_source); + const bool use_filters = use_row_filters(sspreadsheet); - if (BLI_listbase_is_empty(&sspreadsheet.row_filters) && !use_selection) { + /* Avoid allocating an array if no row filtering is necessary. */ + if (!(use_filters || use_selection)) { return IndexRange(tot_rows).as_span(); } Array<bool> rows_included(tot_rows, true); - LISTBASE_FOREACH (const SpreadsheetRowFilter *, row_filter, &sspreadsheet.row_filters) { - if (row_filter->flag & SPREADSHEET_ROW_FILTER_ENABLED) { - apply_row_filter(spreadsheet_layout, *row_filter, rows_included); + if (use_filters) { + LISTBASE_FOREACH (const SpreadsheetRowFilter *, row_filter, &sspreadsheet.row_filters) { + if (row_filter->flag & SPREADSHEET_ROW_FILTER_ENABLED) { + apply_row_filter(spreadsheet_layout, *row_filter, rows_included); + } } } if (use_selection) { const GeometryDataSource *geometry_data_source = dynamic_cast<const GeometryDataSource *>( &data_source); - geometry_data_source->apply_selection_filter(rows_included); } diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.hh b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.hh index 6254175162b..4835a73b06b 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.hh +++ b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.hh @@ -23,8 +23,6 @@ namespace blender::ed::spreadsheet { -bool spreadsheet_data_source_has_selection_filter(const DataSource &data_source); - Span<int64_t> spreadsheet_filter_rows(const SpaceSpreadsheet &sspreadsheet, const SpreadsheetLayout &spreadsheet_layout, const DataSource &data_source, |