This patch adds support for filtering rows based on rules and values. Filters will work for any attribute data source, they are a property of the spreadsheet rather than of the attribute system. The properties displayed in the row filter can depend on data type of the currently visible column with that name. If the name is no longer visible, the row filter filter is grayed out, but it will remember the value until a column with its name is visible again. Note: The comments in `screen.c` combined with tagging the sidebar for redraw after the main region point to a lack of understanding or technical debt, that is a point to improve in the future. **Future Improvements** * T89272: A search menu for visible columns when adding a new filter. * T89273: Possibly a "Range" operation. Differential Revision: https://developer.blender.org/D10959
106 lines
3.2 KiB
C++
106 lines
3.2 KiB
C++
/*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
#include "BLI_string_ref.hh"
|
|
|
|
#include "spreadsheet_cell_value.hh"
|
|
|
|
namespace blender::ed::spreadsheet {
|
|
|
|
/**
|
|
* This represents a column in a spreadsheet. It has a name and provides a value for all the cells
|
|
* in the column.
|
|
*/
|
|
class ColumnValues {
|
|
protected:
|
|
eSpreadsheetColumnValueType type_;
|
|
std::string name_;
|
|
int size_;
|
|
|
|
public:
|
|
ColumnValues(const eSpreadsheetColumnValueType type, std::string name, const int size)
|
|
: type_(type), name_(std::move(name)), size_(size)
|
|
{
|
|
}
|
|
|
|
virtual ~ColumnValues() = default;
|
|
|
|
virtual void get_value(int index, CellValue &r_cell_value) const = 0;
|
|
|
|
eSpreadsheetColumnValueType type() const
|
|
{
|
|
return type_;
|
|
}
|
|
|
|
StringRefNull name() const
|
|
{
|
|
return name_;
|
|
}
|
|
|
|
int size() const
|
|
{
|
|
return size_;
|
|
}
|
|
|
|
/* The default width of newly created columns, in UI units. */
|
|
float default_width = 0.0f;
|
|
};
|
|
|
|
/* Utility class for the function below. */
|
|
template<typename GetValueF> class LambdaColumnValues : public ColumnValues {
|
|
private:
|
|
GetValueF get_value_;
|
|
|
|
public:
|
|
LambdaColumnValues(const eSpreadsheetColumnValueType type,
|
|
std::string name,
|
|
int size,
|
|
GetValueF get_value)
|
|
: ColumnValues(type, std::move(name), size), get_value_(std::move(get_value))
|
|
{
|
|
}
|
|
|
|
void get_value(int index, CellValue &r_cell_value) const final
|
|
{
|
|
get_value_(index, r_cell_value);
|
|
}
|
|
};
|
|
|
|
/* Utility function that simplifies creating a spreadsheet column from a lambda function. */
|
|
template<typename GetValueF>
|
|
std::unique_ptr<ColumnValues> column_values_from_function(const eSpreadsheetColumnValueType type,
|
|
std::string name,
|
|
const int size,
|
|
GetValueF get_value,
|
|
const float default_width = 0.0f)
|
|
{
|
|
std::unique_ptr<ColumnValues> column_values = std::make_unique<LambdaColumnValues<GetValueF>>(
|
|
type, std::move(name), size, std::move(get_value));
|
|
column_values->default_width = default_width;
|
|
return column_values;
|
|
}
|
|
|
|
static constexpr float default_float_column_width = 3;
|
|
static constexpr float default_float2_column_width = 2 * default_float_column_width;
|
|
static constexpr float default_float3_column_width = 3 * default_float_column_width;
|
|
static constexpr float default_color_column_width = 4 * default_float_column_width;
|
|
|
|
} // namespace blender::ed::spreadsheet
|