[gnumeric] StyleConditions: avoid set_sheet functionality.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] StyleConditions: avoid set_sheet functionality.
- Date: Sun, 19 Jul 2020 16:08:37 +0000 (UTC)
commit 59a980ed26bbc948d3db938220be7f8466f946cc
Author: Morten Welinder <terra gnome org>
Date: Sun Jul 19 12:07:41 2020 -0400
StyleConditions: avoid set_sheet functionality.
Insist that the sheet is provided when objects are created.
src/mstyle.c | 3 +-
src/style-conditions.c | 77 +++++++++++++++++++++++++-------------------------
src/style-conditions.h | 5 +---
3 files changed, 41 insertions(+), 44 deletions(-)
---
diff --git a/src/mstyle.c b/src/mstyle.c
index 8c29fdb5c0..c0142ef317 100644
--- a/src/mstyle.c
+++ b/src/mstyle.c
@@ -1000,8 +1000,7 @@ gnm_style_linked_sheet_changed (GnmStyle *style)
if (elem_is_set (style, MSTYLE_CONDITIONS) &&
style->conditions &&
gnm_style_conditions_get_sheet (style->conditions) != sheet) {
- GnmStyleConditions *new_c = gnm_style_conditions_dup (style->conditions);
- gnm_style_conditions_set_sheet (new_c, sheet);
+ GnmStyleConditions *new_c = gnm_style_conditions_dup_to (style->conditions, sheet);
gnm_style_set_conditions (style, new_c);
}
}
diff --git a/src/style-conditions.c b/src/style-conditions.c
index 13e796ad51..c14b6eec3b 100644
--- a/src/style-conditions.c
+++ b/src/style-conditions.c
@@ -131,20 +131,21 @@ gnm_style_cond_new (GnmStyleCondOp op, Sheet *sheet)
}
/**
- * gnm_style_cond_dup:
+ * gnm_style_cond_dup_to:
* @src: #GnmStyleCond
+ * @sheet: Sheet that the duplicate should live on
*
* Returns: (transfer full): the newly allocated #GnmStyleCond.
**/
-GnmStyleCond *
-gnm_style_cond_dup (GnmStyleCond const *src)
+static GnmStyleCond *
+gnm_style_cond_dup_to (GnmStyleCond const *src, Sheet *sheet)
{
GnmStyleCond *dst;
unsigned ui;
g_return_val_if_fail (src != NULL, NULL);
- dst = gnm_style_cond_new (src->op, gnm_style_cond_get_sheet (src));
+ dst = gnm_style_cond_new (src->op, sheet);
gnm_style_cond_set_overlay (dst, src->overlay);
for (ui = 0; ui < 2; ui++)
gnm_style_cond_set_expr (dst, dependent_managed_get_expr (&src->deps[ui]), ui);
@@ -152,6 +153,20 @@ gnm_style_cond_dup (GnmStyleCond const *src)
return dst;
}
+/**
+ * gnm_style_cond_dup:
+ * @src: #GnmStyleCond
+ *
+ * Returns: (transfer full): the newly allocated #GnmStyleCond.
+ **/
+static GnmStyleCond *
+gnm_style_cond_dup (GnmStyleCond const *src)
+{
+ g_return_val_if_fail (src != NULL, NULL);
+
+ return gnm_style_cond_dup_to (src, gnm_style_cond_get_sheet (src));
+}
+
void
gnm_style_cond_free (GnmStyleCond *cond)
{
@@ -194,18 +209,6 @@ gnm_style_cond_get_sheet (GnmStyleCond const *cond)
return cond->deps[0].base.sheet;
}
-void
-gnm_style_cond_set_sheet (GnmStyleCond *cond, Sheet *sheet)
-{
- int ui;
-
- g_return_if_fail (cond != NULL);
- g_return_if_fail (IS_SHEET (sheet));
-
- for (ui = 0; ui < 2; ui++)
- dependent_managed_set_sheet (&cond->deps[ui], sheet);
-}
-
/**
* gnm_style_cond_get_expr:
* @cond: #GnmStyleCond
@@ -732,33 +735,49 @@ gnm_style_conditions_new (Sheet *sheet)
}
/**
- * gnm_style_conditions_dup:
+ * gnm_style_conditions_dup_to:
* @sc: (nullable): the #GnmStyleConditions to duplicate.
+ * @sheet: Sheet that the duplicate should live on
*
* Returns: (transfer full) (nullable): the duplicated #GnmStyleConditions.
**/
GnmStyleConditions *
-gnm_style_conditions_dup (GnmStyleConditions const *sc)
+gnm_style_conditions_dup_to (GnmStyleConditions const *sc, Sheet *sheet)
{
GnmStyleConditions *dup;
GPtrArray const *ga;
if (sc == NULL)
return NULL;
- dup = gnm_style_conditions_new (gnm_style_conditions_get_sheet (sc));
+ dup = gnm_style_conditions_new (sheet);
ga = gnm_style_conditions_details (sc);
if (ga != NULL) {
guint i;
GPtrArray *ga_dup = g_ptr_array_sized_new (ga->len);
for (i = 0; i < ga->len; i++) {
GnmStyleCond *cond = g_ptr_array_index (ga, i);
- g_ptr_array_add (ga_dup, gnm_style_cond_dup (cond));
+ g_ptr_array_add (ga_dup, gnm_style_cond_dup_to (cond, sheet));
}
dup->conditions = ga_dup;
}
return dup;
}
+
+/**
+ * gnm_style_conditions_dup:
+ * @sc: (nullable): the #GnmStyleConditions to duplicate.
+ *
+ * Returns: (transfer full) (nullable): the duplicated #GnmStyleConditions.
+ **/
+GnmStyleConditions *
+gnm_style_conditions_dup (GnmStyleConditions const *sc)
+{
+ return sc
+ ? gnm_style_conditions_dup_to (sc, gnm_style_conditions_get_sheet (sc))
+ : NULL;
+}
+
#define MIX(H) do { \
H *= G_GUINT64_CONSTANT(123456789012345); \
H ^= (H >> 31); \
@@ -846,24 +865,6 @@ gnm_style_conditions_get_sheet (GnmStyleConditions const *sc)
return sc->sheet;
}
-void
-gnm_style_conditions_set_sheet (GnmStyleConditions *sc, Sheet *sheet)
-{
- GPtrArray const *ga;
- unsigned ui;
-
- g_return_if_fail (sc != NULL);
- g_return_if_fail (IS_SHEET (sheet));
-
- sc->sheet = sheet;
- ga = gnm_style_conditions_details (sc);
- for (ui = 0; ga && ui < ga->len; ui++) {
- GnmStyleCond *cond = g_ptr_array_index (ga, ui);
- gnm_style_cond_set_sheet (cond, sheet);
- }
-}
-
-
/**
* gnm_style_conditions_details:
* @sc: #GnmStyleConditions
diff --git a/src/style-conditions.h b/src/style-conditions.h
index 3a71ab2443..5297c9e525 100644
--- a/src/style-conditions.h
+++ b/src/style-conditions.h
@@ -45,7 +45,6 @@ typedef struct {
GType gnm_style_cond_get_type (void);
GnmStyleCond *gnm_style_cond_new (GnmStyleCondOp op, Sheet *sheet);
void gnm_style_cond_free (GnmStyleCond *cond);
-GnmStyleCond *gnm_style_cond_dup (GnmStyleCond const *src);
gboolean gnm_style_cond_is_valid (GnmStyleCond const *cond);
void gnm_style_cond_set_overlay (GnmStyleCond *cond,
@@ -61,11 +60,11 @@ GnmExprTop const *gnm_style_cond_get_alternate_expr (GnmStyleCond const *cond);
void gnm_style_cond_canonicalize (GnmStyleCond *cond);
Sheet *gnm_style_cond_get_sheet (GnmStyleCond const *cond);
-void gnm_style_cond_set_sheet (GnmStyleCond *cond, Sheet *sheet);
GType gnm_style_conditions_get_type (void);
GnmStyleConditions *gnm_style_conditions_new (Sheet *sheet);
GnmStyleConditions *gnm_style_conditions_dup (GnmStyleConditions const *sc);
+GnmStyleConditions *gnm_style_conditions_dup_to (GnmStyleConditions const *sc, Sheet *sheet);
GPtrArray const *gnm_style_conditions_details (GnmStyleConditions const *sc);
void gnm_style_conditions_insert (GnmStyleConditions *sc,
GnmStyleCond const *cond,
@@ -78,8 +77,6 @@ int gnm_style_conditions_eval (GnmStyleConditions const *sc,
GnmEvalPos const *pos);
Sheet *gnm_style_conditions_get_sheet (GnmStyleConditions const *sc);
-void gnm_style_conditions_set_sheet (GnmStyleConditions *sc,
- Sheet *sheet);
guint32 gnm_style_conditions_hash (GnmStyleConditions const *sc);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]