[gnumeric] scenario: fix duplication.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnumeric] scenario: fix duplication.
- Date: Thu, 26 Nov 2009 04:50:21 +0000 (UTC)
commit bd9922e798e18d3e1248924452312961db60829e
Author: Morten Welinder <terra gnome org>
Date: Wed Nov 25 23:50:02 2009 -0500
scenario: fix duplication.
src/tools/scenarios.c | 75 +++++++++++++++++++++----------------------------
src/tools/scenarios.h | 2 +-
2 files changed, 33 insertions(+), 44 deletions(-)
---
diff --git a/src/tools/scenarios.c b/src/tools/scenarios.c
index 15305c0..cff33ea 100644
--- a/src/tools/scenarios.c
+++ b/src/tools/scenarios.c
@@ -58,6 +58,15 @@ gnm_scenario_item_free (GnmScenarioItem *sci)
g_free (sci);
}
+static GnmScenarioItem *
+gnm_scenario_item_dup (GnmScenarioItem *src)
+{
+ GnmScenarioItem *dst = gnm_scenario_item_new (src->dep.sheet);
+ dependent_managed_set_expr (&dst->dep, src->dep.texpr);
+ dst->value = value_dup (src->value);
+ return dst;
+}
+
void
gnm_scenario_item_set_range (GnmScenarioItem *sci, const GnmSheetRange *sr)
{
@@ -265,7 +274,7 @@ gnm_scenario_apply (GnmScenario *sc)
}
char *
-gnm_scenario_get_range_str (GnmScenario *sc)
+gnm_scenario_get_range_str (const GnmScenario *sc)
{
GString *str;
GSList *l;
@@ -289,59 +298,24 @@ gnm_scenario_get_range_str (GnmScenario *sc)
/* ------------------------------------------------------------------------- */
-typedef struct {
- gboolean expr_flag;
- Sheet *sheet;
-} collect_cb_t;
-
-static GnmValue *
-collect_cb (int col, int row, GnmValue *v, collect_cb_t *p)
-{
- GnmCell *cell = sheet_cell_fetch (p->sheet, col, row);
-
- p->expr_flag |= gnm_cell_has_expr (cell);
-
- return value_dup (cell->value);
-}
-
/* Scenario: Duplicate sheet ***********************************************/
-typedef struct {
- int rows;
- int cols;
- int col_offset;
- int row_offset;
- GnmScenario *dest;
-} copy_cb_t;
-
-static GnmValue *
-copy_cb (int col, int row, GnmValue *v, copy_cb_t *p)
-{
- p->dest->changing_cells [col - p->col_offset +
- (row - p->row_offset) * p->cols] =
- value_dup (v);
-
- return v;
-}
-
GnmScenario *
gnm_scenario_dup (GnmScenario *src, Sheet *new_sheet)
{
GnmScenario *dst;
- copy_cb_t cb;
+ GSList *l;
dst = gnm_scenario_new (src->name, new_sheet);
gnm_scenario_set_comment (dst, src->comment);
dst->range = src->range;
- cb.rows = src->range.end.row - src->range.start.row + 1;
- cb.cols = src->range.end.col - src->range.start.col + 1;
- cb.col_offset = src->range.start.col;
- cb.row_offset = src->range.start.row;
- cb.dest = dst;
-
- dst->changing_cells = g_new (GnmValue *, cb.rows * cb.cols);
- scenario_for_each_value (src, (ScenarioValueCB) copy_cb, &cb);
+ for (l = src->items; l; l = l->next) {
+ GnmScenarioItem *src_sci = l->data;
+ GnmScenarioItem *dst_sci = gnm_scenario_item_dup (src_sci);
+ dst->items = g_slist_prepend (dst->items, dst_sci);
+ }
+ dst->items = g_slist_reverse (dst->items);
return dst;
}
@@ -354,6 +328,21 @@ show_cb (int col, int row, GnmValue *v, data_analysis_output_t *dao)
return v;
}
+typedef struct {
+ gboolean expr_flag;
+ Sheet *sheet;
+} collect_cb_t;
+
+static GnmValue *
+collect_cb (int col, int row, GnmValue *v, collect_cb_t *p)
+{
+ GnmCell *cell = sheet_cell_fetch (p->sheet, col, row);
+
+ p->expr_flag |= gnm_cell_has_expr (cell);
+
+ return value_dup (cell->value);
+}
+
GnmScenario *
scenario_show (GnmScenario *s,
GnmScenario *old_values,
diff --git a/src/tools/scenarios.h b/src/tools/scenarios.h
index 6289375..7f08c3d 100644
--- a/src/tools/scenarios.h
+++ b/src/tools/scenarios.h
@@ -56,7 +56,7 @@ void gnm_scenario_add_area (GnmScenario *sc, const GnmSheetRange *sr);
GOUndo *gnm_scenario_apply (GnmScenario *sc);
-char *gnm_scenario_get_range_str (GnmScenario *sc);
+char *gnm_scenario_get_range_str (const GnmScenario *sc);
/* ------------------------------------------------------------------------- */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]