Commit 1651daaf authored by Morten Welinder's avatar Morten Welinder

CondFormat: recognize equal-style regions with conditional formats.

We used to compare mstyle->conditions by pointer.  This implements proper
equality.
parent 27ced942
2017-01-19 Morten Welinder <terra@gnome.org>
* src/mstyle.c (ELEM_IS_EQ): Don't compare conditions by pointer.
* src/style-conditions.c (gnm_style_conditions_equal): New
function.
2016-12-08 Morten Welinder <terra@gnome.org>
* src/mathfunc.c (gnm_linear_solve): Use proper matrix type. All
......
......@@ -9,6 +9,7 @@ Morten:
* Speed up sstest part of test suite.
* Bring documentation build into the 21 century.
* Non-linear solver improvements.
* Avoid atomizing style regions with conditional formats.
--------------------------------------------------------------------------
Gnumeric 1.12.32
......
......@@ -393,11 +393,13 @@ gnm_style_hash (gconstpointer style)
: (elem == MSTYLE_INPUT_MSG \
? a->input_msg == b->input_msg \
: (elem == MSTYLE_CONDITIONS \
? a->conditions == b->conditions \
? (a->conditions == b->conditions || \
(a->conditions && \
gnm_style_conditions_equal (a->conditions, b->conditions))) \
: FALSE)))))))))))))))))))))))))
/*
* Note: the above is suboptimal from validation and down.
* Note: the above is suboptimal for validation, hlink, input_msg.
*
* We are comparing pointers (which at least safely matches what we do
* with the hash), but I think we want proper equality.
......
......@@ -764,6 +764,57 @@ gnm_style_conditions_hash (GnmStyleConditions const *sc)
#undef MIX
/**
* gnm_style_conditions_equal:
* @sca: first #GnmStyleConditions to compare.
* @scb: second #GnmStyleConditions to compare.
*
* Returns: %TRUE if the conditions are equal.
**/
gboolean
gnm_style_conditions_equal (GnmStyleConditions const *sca,
GnmStyleConditions const *scb)
{
GPtrArray const *ga, *gb;
unsigned ui;
g_return_val_if_fail (sca != NULL, FALSE);
g_return_val_if_fail (scb != NULL, FALSE);
if (sca->sheet != scb->sheet)
return FALSE;
ga = gnm_style_conditions_details (sca);
gb = gnm_style_conditions_details (scb);
if (!ga || !gb)
return ga == gb;
if (ga->len != gb->len)
return FALSE;
for (ui = 0; ui < ga->len; ui++) {
GnmStyleCond *ca = g_ptr_array_index (ga, ui);
GnmStyleCond *cb = g_ptr_array_index (gb, ui);
unsigned oi, N;
if (ca->op != cb->op)
return FALSE;
if (!gnm_style_equal (ca->overlay, cb->overlay))
return FALSE;
N = gnm_style_cond_op_operands (ca->op);
for (oi = 0; oi < N; oi++) {
if (ca->deps[oi].sheet != cb->deps[oi].sheet)
return FALSE;
if (!gnm_expr_top_equal (ca->deps[oi].texpr,
cb->deps[oi].texpr))
return FALSE;
}
}
return TRUE;
}
/**
* gnm_style_conditions_get_sheet:
......
......@@ -84,6 +84,9 @@ void gnm_style_conditions_set_sheet (GnmStyleConditions *sc,
guint32 gnm_style_conditions_hash (GnmStyleConditions const *sc);
gboolean gnm_style_conditions_equal (GnmStyleConditions const *sca,
GnmStyleConditions const *scb);
G_END_DECLS
#endif /* _GNM_STYLE_CONDITIONS_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment