Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-04-09 11:20:46 +0300
committerJacques Lucke <jacques@blender.org>2021-04-09 11:20:46 +0300
commit75491fe1002122f19fc9fe8eae941a406b81706a (patch)
tree16a05f5b5ccc7087595ce27656aaa60a5f5c118a /source/blender/editors/space_spreadsheet/spreadsheet_column_values.hh
parent22574f741c4e4d142c7068316296d24bbfc2a12c (diff)
Spreadsheet: persistent column storage and data source
A `DataSource` provides columns for the spreadsheet to display. Every column has a SpreadsheetColumnID as identifier. Columns are not generated eagerly anymore, instead the main spreadsheet code can request a column from a data source with an column identifier. The column identifiers can be stored in DNA and allow us to store persistent data per column. On the user level the only thing that changes is that columns are not shown in alphabetical order anymore. Instead, new columns are always added on the left. The behavior can be changed, however I'd prefer not to automate this too much currently. I think we should just add operators to hide/reorder/resize columns soonish. Differential Revision: https://developer.blender.org/D10901
Diffstat (limited to 'source/blender/editors/space_spreadsheet/spreadsheet_column_values.hh')
-rw-r--r--source/blender/editors/space_spreadsheet/spreadsheet_column_values.hh84
1 files changed, 84 insertions, 0 deletions
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_column_values.hh b/source/blender/editors/space_spreadsheet/spreadsheet_column_values.hh
new file mode 100644
index 00000000000..58a2776e0fc
--- /dev/null
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_column_values.hh
@@ -0,0 +1,84 @@
+/*
+ * 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 "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:
+ std::string name_;
+ int size_;
+
+ public:
+ ColumnValues(std::string name, const int size) : name_(std::move(name)), size_(size)
+ {
+ }
+
+ virtual ~ColumnValues() = default;
+
+ virtual void get_value(int index, CellValue &r_cell_value) const = 0;
+
+ 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(std::string name, int size, GetValueF get_value)
+ : ColumnValues(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(std::string name,
+ int size,
+ GetValueF get_value)
+{
+ return std::make_unique<LambdaColumnValues<GetValueF>>(
+ std::move(name), size, std::move(get_value));
+}
+
+} // namespace blender::ed::spreadsheet