[gnumeric] Styles: fix optimizer to not ignore apparently-empty cells.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Styles: fix optimizer to not ignore apparently-empty cells.
- Date: Tue, 17 May 2011 17:56:13 +0000 (UTC)
commit 5f9d29d8a512cda273cb63be63a3388a00fdace5
Author: Morten Welinder <terra gnome org>
Date: Tue May 17 13:55:03 2011 -0400
Styles: fix optimizer to not ignore apparently-empty cells.
We should look at *all* cells, including those with expressions and
those that happen to have empty values.
ChangeLog | 3 +++
src/sheet.c | 38 ++++++++++++++++++++++++++++++++++++--
src/sheet.h | 1 +
3 files changed, 40 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e000668..d585654 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2011-05-17 Morten Welinder <terra gnome org>
+ * src/sheet.c (sheet_colrow_optimize): Use sheet_get_cells_extent.
+ (sheet_get_cells_extent): New function.
+
* src/xml-sax-write.c (xml_write_named_expressions): Do nothing if
there are no names.
diff --git a/src/sheet.c b/src/sheet.c
index 83f68d4..76bacac 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -2014,6 +2014,7 @@ sheet_colrow_gutter (Sheet *sheet, gboolean is_cols, int max_outline)
struct sheet_extent_data {
GnmRange range;
gboolean spans_and_merges_extend;
+ gboolean ignore_empties;
};
static void
@@ -2022,7 +2023,7 @@ cb_sheet_get_extent (gpointer ignored, gpointer value, gpointer data)
GnmCell const *cell = (GnmCell const *) value;
struct sheet_extent_data *res = data;
- if (gnm_cell_is_empty (cell))
+ if (res->ignore_empties && gnm_cell_is_empty (cell))
return;
/* Remember the first cell is the min & max */
@@ -2067,6 +2068,9 @@ cb_sheet_get_extent (gpointer ignored, gpointer value, gpointer data)
* NOTE: When spans_and_merges_extend is TRUE, this function will calculate
* all spans. That might be expensive.
*
+ * NOTE: This refers to *visible* contents. Cells with empty values, including
+ * formulas with such values, are *ignored.
+ *
* Return value: the range.
**/
GnmRange
@@ -2084,6 +2088,7 @@ sheet_get_extent (Sheet const *sheet, gboolean spans_and_merges_extend)
closure.range.end.col = 0;
closure.range.end.row = 0;
closure.spans_and_merges_extend = spans_and_merges_extend;
+ closure.ignore_empties = TRUE;
sheet_cell_foreach (sheet, &cb_sheet_get_extent, &closure);
@@ -2112,6 +2117,35 @@ sheet_get_extent (Sheet const *sheet, gboolean spans_and_merges_extend)
return closure.range;
}
+/**
+ * sheet_get_cells_extent:
+ * @sheet: the sheet
+ *
+ * calculates the area occupied by cells, including empty cells.
+ *
+ * Return value: the range.
+ **/
+GnmRange
+sheet_get_cells_extent (Sheet const *sheet)
+{
+ static GnmRange const dummy = { { 0,0 }, { 0,0 } };
+ struct sheet_extent_data closure;
+
+ g_return_val_if_fail (IS_SHEET (sheet), dummy);
+
+ closure.range.start.col = gnm_sheet_get_last_col (sheet);
+ closure.range.start.row = gnm_sheet_get_last_row (sheet);
+ closure.range.end.col = 0;
+ closure.range.end.row = 0;
+ closure.spans_and_merges_extend = FALSE;
+ closure.ignore_empties = FALSE;
+
+ sheet_cell_foreach (sheet, &cb_sheet_get_extent, &closure);
+
+ return closure.range;
+}
+
+
GnmRange *
sheet_get_nominal_printarea (Sheet const *sheet)
{
@@ -3456,7 +3490,7 @@ sheet_colrow_optimize (Sheet *sheet)
g_return_if_fail (IS_SHEET (sheet));
- extent = sheet_get_extent (sheet, TRUE);
+ extent = sheet_get_cells_extent (sheet);
sheet_colrow_optimize1 (gnm_sheet_get_max_cols (sheet),
extent.end.col,
diff --git a/src/sheet.h b/src/sheet.h
index d0307bf..008693d 100644
--- a/src/sheet.h
+++ b/src/sheet.h
@@ -306,6 +306,7 @@ void sheet_scrollbar_config (Sheet const *s);
void sheet_mark_dirty (Sheet *sheet);
GnmRange sheet_get_extent (Sheet const *sheet,
gboolean spans_and_merges_extend);
+GnmRange sheet_get_cells_extent (Sheet const *sheet);
GnmRange sheet_get_printarea (Sheet const *sheet,
gboolean include_styles,
gboolean ignore_printarea);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]