[gnumeric] Conditional formatting: fix insert/delete col/row problems.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Conditional formatting: fix insert/delete col/row problems.
- Date: Mon, 18 Jan 2021 22:25:24 +0000 (UTC)
commit 47d6c7abc9bbad58e19e0559b72316caa4833cdf
Author: Morten Welinder <terra gnome org>
Date: Mon Jan 18 17:24:19 2021 -0500
Conditional formatting: fix insert/delete col/row problems.
See #547, item 4.
src/sheet-conditions.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++---
src/sheet-conditions.h | 4 ++++
src/sheet-style.c | 11 ----------
src/sheet-style.h | 2 --
src/sheet.c | 5 +++--
5 files changed, 62 insertions(+), 18 deletions(-)
---
diff --git a/src/sheet-conditions.c b/src/sheet-conditions.c
index 1c9ebde92..72639ad22 100644
--- a/src/sheet-conditions.c
+++ b/src/sheet-conditions.c
@@ -200,7 +200,7 @@ sheet_conditions_uninit (Sheet *sheet)
/**
* sheet_conditions_share_conditions_add:
- * @conds: (transfer none):
+ * @conds: (transfer none):
*
* Returns: (transfer none) (nullable): Conditions equivalent to @conds, or
* %NULL if @conds had not been seen before.
@@ -227,7 +227,7 @@ sheet_conditions_share_conditions_add (GnmStyleConditions *conds)
/**
* sheet_conditions_share_conditions_remove:
- * @conds: (transfer none):
+ * @conds: (transfer none):
*
* This notifies the sheet conditions manager that one use of the shared
* conditions has gone away.
@@ -374,7 +374,7 @@ sheet_conditions_remove (Sheet *sheet, GnmRange const *r, GnmStyle *style)
return;
}
- g_printerr ("Removing style %p from %s\n", style, range_as_string (r));
+ //g_printerr ("Removing style %p from %s\n", style, range_as_string (r));
g = find_group (cd, style);
if (!g) {
g_warning ("Removing conditional style we don't have?");
@@ -436,6 +436,58 @@ sheet_conditions_remove (Sheet *sheet, GnmRange const *r, GnmStyle *style)
// ----------------------------------------------------------------------------
+static void
+lu1 (GnmDependent *dep, gboolean qlink)
+{
+ if (dep == NULL || dep->texpr == NULL ||
+ qlink == !!dependent_is_linked (dep))
+ return;
+
+ if (qlink)
+ dependent_link (dep);
+ else
+ dependent_unlink (dep);
+}
+
+void
+sheet_conditions_link_unlink_dependents (Sheet *sheet,
+ GnmRange const *r,
+ gboolean qlink)
+{
+ GnmSheetConditionsData *cd = sheet->conditions;
+ GHashTableIter hiter;
+ gpointer value;
+
+ g_hash_table_iter_init (&hiter, cd->groups);
+ while (g_hash_table_iter_next (&hiter, NULL, &value)) {
+ CSGroup *g = value;
+ unsigned ui, ri;
+ gboolean overlap = (r == NULL);
+ GPtrArray const *ga;
+
+ for (ri = 0; !overlap && ri < g->ranges->len; ri++) {
+ GnmRange const *r1 = &g_array_index (g->ranges, GnmRange, ri);
+ if (range_overlap (r, r1))
+ overlap = TRUE;
+ }
+
+ if (!overlap)
+ continue;
+
+ lu1 (&g->dep.base, qlink);
+
+ ga = gnm_style_conditions_details (g->conds);
+ for (ui = 0; ui < (ga ? ga->len : 0u); ui++) {
+ GnmStyleCond *cond = g_ptr_array_index (ga, ui);
+ unsigned ix;
+ for (ix = 0; ix < G_N_ELEMENTS (cond->deps); ix++)
+ lu1 (&cond->deps[ix].base, qlink);
+ }
+ }
+}
+
+// ----------------------------------------------------------------------------
+
static void
set_group_pos_and_expr (CSGroup *g, const GnmCellPos *pos, GnmExprTop const *texpr)
{
diff --git a/src/sheet-conditions.h b/src/sheet-conditions.h
index a2ac40030..618793016 100644
--- a/src/sheet-conditions.h
+++ b/src/sheet-conditions.h
@@ -18,6 +18,10 @@ void sheet_conditions_remove (Sheet *sheet, GnmRange const *r, GnmStyle *style);
void sheet_conditions_simplify (Sheet *sheet);
void sheet_conditions_dump (Sheet *sheet);
+void sheet_conditions_link_unlink_dependents (Sheet *sheet,
+ GnmRange const *r,
+ gboolean qlink);
+
G_END_DECLS
#endif
diff --git a/src/sheet-style.c b/src/sheet-style.c
index a092a3697..cfda28e1b 100644
--- a/src/sheet-style.c
+++ b/src/sheet-style.c
@@ -328,17 +328,6 @@ rstyle_apply (GnmStyle **old, ReplacementStyle *rs, GnmRange const *r)
}
}
-void
-sheet_style_clear_style_dependents (Sheet *sheet, GnmRange const *r)
-{
- GSList *styles = sh_all_styles (sheet->style_data->style_hash);
- g_slist_foreach (styles,
- (GFunc)gnm_style_unlink_dependents,
- (gpointer)r);
- g_slist_free (styles);
-}
-
-
/****************************************************************************/
typedef enum {
diff --git a/src/sheet-style.h b/src/sheet-style.h
index a5b319be6..a96f2bedd 100644
--- a/src/sheet-style.h
+++ b/src/sheet-style.h
@@ -108,8 +108,6 @@ void sheet_style_unlink (Sheet *sheet, GnmStyle *st);
void sheet_style_optimize (Sheet *sheet);
-void sheet_style_clear_style_dependents (Sheet *sheet, GnmRange const *r);
-
G_END_DECLS
#endif /* _GNM_SHEET_STYLE_H_ */
diff --git a/src/sheet.c b/src/sheet.c
index 1b3ebf56a..1bf16e09a 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -5392,8 +5392,8 @@ sheet_insdel_colrow (Sheet *sheet, int pos, int count,
reloc_info.origin_sheet = reloc_info.target_sheet = sheet;
parse_pos_init_sheet (&reloc_info.pos, sheet);
- /* 2. Get rid of style dependents, see #741197. */
- sheet_style_clear_style_dependents (sheet, &change_zone);
+ // 2. Get rid of style dependents, see #741197.
+ sheet_conditions_link_unlink_dependents (sheet, &change_zone, FALSE);
/* 3. Invalidate references to kill zone. */
if (is_insert) {
@@ -5431,6 +5431,7 @@ sheet_insdel_colrow (Sheet *sheet, int pos, int count,
/* 7. Move formatting. */
sheet_style_insdel_colrow (&reloc_info);
+ sheet_conditions_link_unlink_dependents (sheet, NULL, TRUE);
/* 8. Move objects. */
sheet_objects_relocate (&reloc_info, FALSE, pundo);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]