[gnumeric] scenarios: start cleaning up.



commit f4a712addceb682f8f9aadee2d2eaabee28a24d3
Author: Morten Welinder <terra gnome org>
Date:   Tue Nov 24 11:24:55 2009 -0500

    scenarios: start cleaning up.

 src/commands.c                 |    6 +-
 src/commands.h                 |    4 +-
 src/dialogs/dialog-scenarios.c |   14 ++--
 src/dialogs/dialog-solver.c    |    2 +-
 src/sheet.c                    |   11 ---
 src/tools/ChangeLog            |    6 ++
 src/tools/scenarios.c          |  182 ++++++---------------------------------
 src/tools/scenarios.h          |   31 +++----
 src/xml-sax-write.c            |    2 +-
 9 files changed, 60 insertions(+), 198 deletions(-)
---
diff --git a/src/commands.c b/src/commands.c
index ba874ea..28d6e2a 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -5967,7 +5967,7 @@ cmd_remove_name (WorkbookControl *wbc, GnmNamedExpr *nexpr)
 
 typedef struct {
 	GnmCommand cmd;
-	scenario_t     *scenario;
+	GnmScenario     *scenario;
 } CmdScenarioAdd;
 
 MAKE_GNM_COMMAND (CmdScenarioAdd, cmd_scenario_add, NULL)
@@ -6005,7 +6005,7 @@ cmd_scenario_add_finalize (GObject *cmd)
 }
 
 gboolean
-cmd_scenario_add (WorkbookControl *wbc, scenario_t *s, Sheet *sheet)
+cmd_scenario_add (WorkbookControl *wbc, GnmScenario *s, Sheet *sheet)
 {
 	CmdScenarioAdd *me;
 
@@ -6053,7 +6053,7 @@ cmd_scenario_mngr_undo (GnmCommand *cmd,
 			G_GNUC_UNUSED WorkbookControl *wbc)
 {
 	CmdScenarioMngr *me = CMD_SCENARIO_MNGR (cmd);
-	scenario_t      *tmp;
+	GnmScenario      *tmp;
 	data_analysis_output_t dao;
 
 	dao_init_new_sheet (&dao);
diff --git a/src/commands.h b/src/commands.h
index c93de89..bcd47e7 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -113,9 +113,9 @@ gboolean cmd_define_name	(WorkbookControl *wbc, char const *name,
 gboolean cmd_remove_name        (WorkbookControl *wbc, GnmNamedExpr *nexpr);
 
 /* FIXME: figure out how to resolve these better.  */
-struct _scenario_t;
+struct GnmScenario_;
 struct _scenario_cmd_t;
-gboolean cmd_scenario_add (WorkbookControl *wbc, struct _scenario_t *s, Sheet *sheet);
+gboolean cmd_scenario_add (WorkbookControl *wbc, struct GnmScenario_ *s, Sheet *sheet);
 gboolean cmd_scenario_mngr (WorkbookControl *wbc, struct _scenario_cmd_t *sc, Sheet *sheet);
 
 /* FIXME: figure out how to resolve this better.  */
diff --git a/src/dialogs/dialog-scenarios.c b/src/dialogs/dialog-scenarios.c
index 1b334c9..5b17ab7 100644
--- a/src/dialogs/dialog-scenarios.c
+++ b/src/dialogs/dialog-scenarios.c
@@ -59,8 +59,8 @@ struct _scenario_state {
         GtkWidget  *scenarios_treeview;
 	GSList     *new_report_sheets;
 
-	scenario_t *old_values;
-	scenario_t *current;
+	GnmScenario *old_values;
+	GnmScenario *current;
 };
 
 
@@ -70,7 +70,7 @@ static gboolean
 scenario_name_used (const GList *scenarios, const gchar *name)
 {
 	while (scenarios != NULL) {
-		const scenario_t *s = scenarios->data;
+		const GnmScenario *s = scenarios->data;
 
 		if (strcmp (s->name, name) == 0)
 			return TRUE;
@@ -115,7 +115,7 @@ scenario_add_ok_clicked_cb (G_GNUC_UNUSED GtkWidget *button,
 	GtkTextIter             start, end;
 	GnmRangeRef const      *rr = NULL;
 	gboolean                res;
-	scenario_t              *scenario;
+	GnmScenario              *scenario;
 
 	cell_range = gnm_expr_entry_parse_as_value
 		(GNM_EXPR_ENTRY (state->base.input_entry), state->base.sheet);
@@ -291,7 +291,7 @@ find_scenario_strs (GList *scenarios, gchar *name,
 	static gchar *buf1 = NULL, *buf2 = NULL;
 
 	while (scenarios) {
-		const scenario_t *scenario = scenarios->data;
+		const GnmScenario *scenario = scenarios->data;
 
 		if (strcmp (scenario->name, name) == 0) {
 			g_free (buf1);
@@ -351,7 +351,7 @@ update_scenarios_treeview (GtkWidget *view, GList *scenarios)
 	  store = gtk_list_store_new (1, G_TYPE_STRING);
 
 	  while (scenarios != NULL) {
-	          scenario_t *s = scenarios->data;
+	          GnmScenario *s = scenarios->data;
 
 	          gtk_list_store_append (store, &iter);
 	          gtk_list_store_set (store, &iter, 0, s->name, -1);
@@ -445,7 +445,7 @@ restore_old_values (ScenariosState *state)
 	dao_init_new_sheet (&dao);
 	dao.sheet = state->base.sheet;
 	scenario_show (wbc, NULL,
-		       (scenario_t *) state->scenario_state->old_values,
+		       (GnmScenario *) state->scenario_state->old_values,
 		       &dao);
 	state->scenario_state->current    = NULL;
 	state->scenario_state->old_values = NULL;
diff --git a/src/dialogs/dialog-solver.c b/src/dialogs/dialog-solver.c
index 7c31458..7f525ac 100644
--- a/src/dialogs/dialog-solver.c
+++ b/src/dialogs/dialog-solver.c
@@ -779,7 +779,7 @@ solver_add_scenario (SolverState *state, GnmSolverResult *res, gchar const *name
 	GnmSolverParameters *param = state->sheet->solver_parameters;
 	GnmValue         *input_range;
 	gchar const      *comment = _("Optimal solution created by solver.\n");
-	scenario_t       *scenario;
+	GnmScenario       *scenario;
 
 	input_range = gnm_expr_entry_parse_as_value (state->change_cell_entry,
 						     state->sheet);
diff --git a/src/sheet.c b/src/sheet.c
index 475038e..a430038 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -4455,7 +4455,6 @@ sheet_insert_cols (Sheet *sheet, int col, int count,
 		colrow_move (sheet, i, 0, i, gnm_sheet_get_last_row (sheet),
 			     &sheet->cols, i, i + count);
 
-	scenarios_insert_cols (sheet->scenarios, col, count);
 	sheet_colrow_insert_finish (&reloc_info, TRUE, col, count, pundo);
 
 	add_undo_op (pundo, TRUE, sheet_delete_cols,
@@ -4553,7 +4552,6 @@ sheet_delete_cols (Sheet *sheet, int col, int count,
 		colrow_move (sheet, i, 0, i, gnm_sheet_get_last_row (sheet),
 			     &sheet->cols, i, i - count);
 
-	scenarios_delete_cols (sheet->scenarios, col, count);
 	sheet_colrow_delete_finish (&reloc_info, TRUE, col, count, pundo);
 
 	add_undo_op (pundo, TRUE, sheet_insert_cols,
@@ -4629,7 +4627,6 @@ sheet_insert_rows (Sheet *sheet, int row, int count,
 		colrow_move (sheet, 0, i, gnm_sheet_get_last_col (sheet), i,
 			     &sheet->rows, i, i + count);
 
-	scenarios_insert_rows (sheet->scenarios, row, count);
 	sheet_colrow_insert_finish (&reloc_info, FALSE, row, count, pundo);
 
 	add_undo_op (pundo, FALSE, sheet_delete_rows,
@@ -4727,7 +4724,6 @@ sheet_delete_rows (Sheet *sheet, int row, int count,
 		colrow_move (sheet, 0, i, gnm_sheet_get_last_col (sheet), i,
 			     &sheet->rows, i, i - count);
 
-	scenarios_delete_rows (sheet->scenarios, row, count);
 	sheet_colrow_delete_finish (&reloc_info, FALSE, row, count, pundo);
 
 	add_undo_op (pundo, FALSE, sheet_insert_rows,
@@ -4889,13 +4885,6 @@ sheet_move_range (GnmExprRelocateInfo const *rinfo,
 	/* 8. Notify sheet of pending update */
 	sheet_flag_recompute_spans (rinfo->origin_sheet);
 	sheet_flag_status_update_range (rinfo->origin_sheet, &rinfo->origin);
-
-	/* 9. Update the data structures of the tools */
-	if (rinfo->origin_sheet == rinfo->target_sheet)
-		scenarios_move_range (rinfo->origin_sheet->scenarios,
-				      rinfo->origin_sheet,
-				      &rinfo->origin, rinfo->col_offset,
-				      rinfo->row_offset);
 }
 
 static void
diff --git a/src/tools/ChangeLog b/src/tools/ChangeLog
index 69023fb..600c755 100644
--- a/src/tools/ChangeLog
+++ b/src/tools/ChangeLog
@@ -1,3 +1,9 @@
+2009-11-24  Morten Welinder  <terra gnome org>
+
+	* scenarios.c (scenarios_insert_rows, scenarios_insert_cols,
+	scenarios_delete_rows, scenarios_delete_cols,
+	scenarios_move_range): Remove.
+
 2009-11-21 Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* analysis-normality.c: new
diff --git a/src/tools/scenarios.c b/src/tools/scenarios.c
index f697c66..738be0d 100644
--- a/src/tools/scenarios.c
+++ b/src/tools/scenarios.c
@@ -45,16 +45,16 @@
 
 /* Generic stuff **********************************************************/
 
-scenario_t *
+GnmScenario *
 scenario_by_name (GList *scenarios, gchar const *name, gboolean *all_deleted)
 {
-	scenario_t *res = NULL;
+	GnmScenario *res = NULL;
 
 	if (all_deleted)
 		*all_deleted = TRUE;
 
 	while (scenarios != NULL) {
-		scenario_t *s = scenarios->data;
+		GnmScenario *s = scenarios->data;
 
 		if (strcmp (s->name, name) == 0)
 			res = s;
@@ -70,7 +70,7 @@ scenario_by_name (GList *scenarios, gchar const *name, gboolean *all_deleted)
 typedef GnmValue * (*ScenarioValueCB) (int col, int row, GnmValue *v, gpointer data);
 
 static void
-scenario_for_each_value (scenario_t *s, ScenarioValueCB fn, gpointer data)
+scenario_for_each_value (GnmScenario *s, ScenarioValueCB fn, gpointer data)
 {
 	int        i, j, cols, pos;
 
@@ -87,13 +87,13 @@ scenario_for_each_value (scenario_t *s, ScenarioValueCB fn, gpointer data)
 
 /* Scenario: Add ***********************************************************/
 
-static scenario_t *
+static GnmScenario *
 scenario_new (Sheet *sheet, gchar const *name, gchar const *comment)
 {
-	scenario_t *s;
+	GnmScenario *s;
 	GList      *scenarios = sheet->scenarios;
 
-	s = g_new (scenario_t, 1);
+	s = g_new (GnmScenario, 1);
 	s->sheet = sheet;
 
 	/* Check if a scenario having the same name already exists. */
@@ -158,7 +158,7 @@ collect_cb (int col, int row, GnmValue *v, collect_cb_t *p)
  * expression return TRUE so that the user can be warned about it.
  */
 static gboolean
-collect_values (Sheet *sheet, scenario_t *s, GnmValueRange *range)
+collect_values (Sheet *sheet, GnmScenario *s, GnmValueRange *range)
 {
 	int          cols, rows;
 	collect_cb_t cb;
@@ -183,9 +183,9 @@ scenario_add_new (gchar const *name,
 		  gchar const *cell_sel_str,
 		  gchar const *comment,
 		  Sheet *sheet,
-		  scenario_t **new_scenario)
+		  GnmScenario **new_scenario)
 {
-	scenario_t *scenario = scenario_new (sheet, name, comment);
+	GnmScenario *scenario = scenario_new (sheet, name, comment);
 	gboolean    res = collect_values (sheet, scenario, (GnmValueRange *) changing_cells);
 
 	scenario->cell_sel_str = g_strdup (cell_sel_str);
@@ -196,7 +196,7 @@ scenario_add_new (gchar const *name,
 }
 
 void
-scenario_add (Sheet *sheet, scenario_t *scenario)
+scenario_add (Sheet *sheet, GnmScenario *scenario)
 {
 	sheet->scenarios = g_list_append (sheet->scenarios, scenario);
 }
@@ -208,7 +208,7 @@ typedef struct {
 	int        cols;
 	int        col_offset;
 	int        row_offset;
-	scenario_t *dest;
+	GnmScenario *dest;
 } copy_cb_t;
 
 static GnmValue *
@@ -221,13 +221,13 @@ copy_cb (int col, int row, GnmValue *v, copy_cb_t *p)
 	return v;
 }
 
-scenario_t *
-scenario_copy (scenario_t *s, Sheet *new_sheet)
+GnmScenario *
+scenario_copy (GnmScenario *s, Sheet *new_sheet)
 {
-	scenario_t *p;
+	GnmScenario *p;
 	copy_cb_t  cb;
 
-	p = g_new (scenario_t, 1);
+	p = g_new (GnmScenario, 1);
 
 	p->name         = g_strdup (s->name);
 	p->comment      = g_strdup (s->comment);
@@ -272,7 +272,7 @@ cb_value_free (int col, int row, GnmValue *v, gpointer data)
 }
 
 void
-scenario_free (scenario_t *s)
+scenario_free (GnmScenario *s)
 {
 	if (s == NULL)
 		return;
@@ -302,7 +302,7 @@ scenarios_free (GList *list)
 gboolean
 scenario_mark_deleted (GList *scenarios, gchar *name)
 {
-	scenario_t *s;
+	GnmScenario *s;
 	gboolean   all_deleted;
 
 	s = scenario_by_name (scenarios, name, &all_deleted);
@@ -314,7 +314,7 @@ scenario_mark_deleted (GList *scenarios, gchar *name)
 GList *
 scenario_delete (GList *scenarios, gchar *name)
 {
-	scenario_t *s;
+	GnmScenario *s;
 	GList      *list;
 
 	s = scenario_by_name (scenarios, name, NULL);
@@ -335,13 +335,13 @@ show_cb (int col, int row, GnmValue *v, data_analysis_output_t *dao)
 	return v;
 }
 
-scenario_t *
+GnmScenario *
 scenario_show (WorkbookControl        *wbc,
-	       scenario_t             *s,
-	       scenario_t             *old_values,
+	       GnmScenario             *s,
+	       GnmScenario             *old_values,
 	       data_analysis_output_t *dao)
 {
-	scenario_t   *stored_values;
+	GnmScenario   *stored_values;
 	int           rows, cols;
 	collect_cb_t  cb;
 
@@ -374,132 +374,6 @@ scenario_show (WorkbookControl        *wbc,
 	return stored_values;
 }
 
-
-/* Scenario: Insert columns(s)/row(s) *************************************/
-
-static void
-insert_cols (scenario_t *s, int col, int count)
-{
-	if (s->range.start.col >= col) {
-		s->range.start.col += count;
-		s->range.end.col += count;
-
-		/* Scenarios do not allow cross sheet references. */
-
-		/* FIXME: What if we fell off the end?  */
-
-		g_free (s->cell_sel_str);
-		s->cell_sel_str = g_strdup (range_as_string (&s->range));
-	}
-}
-
-void
-scenarios_insert_cols (GList *list, int col, int count)
-{
-	while (list != NULL) {
-		insert_cols (list->data, col, count);
-		list = list->next;
-	}
-}
-
-static void
-insert_rows (scenario_t *s, int row, int count)
-{
-	if (s->range.start.row >= row) {
-		s->range.start.row += count;
-		s->range.end.row += count;
-
-		/* Scenarios do not allow cross sheet references. */
-
-		/* FIXME: What if we fell off the end?  */
-
-		g_free (s->cell_sel_str);
-		s->cell_sel_str = g_strdup (range_as_string (&s->range));
-	}
-}
-
-void
-scenarios_insert_rows (GList *list, int row, int count)
-{
-	while (list != NULL) {
-		insert_rows (list->data, row, count);
-		list = list->next;
-	}
-}
-
-/* Scenario: Delete columns(s)/row(s) *************************************/
-
-static void
-delete_cols (scenario_t *s, int col, int count)
-{
-	if (s->range.start.col >= col) {
-		s->range.start.col -= count;
-		s->range.end.col -= count;
-
-		/* Scenarios do not allow cross sheet references. */
-
-		/* FIXME: What if we fell off the end?  */
-
-		g_free (s->cell_sel_str);
-		s->cell_sel_str = g_strdup (range_as_string (&s->range));
-	}
-}
-
-void
-scenarios_delete_cols (GList *list, int col, int count)
-{
-	while (list != NULL) {
-		delete_cols (list->data, col, count);
-		list = list->next;
-	}
-}
-
-static void
-delete_rows (scenario_t *s, int row, int count)
-{
-	if (s->range.start.row >= row) {
-		s->range.start.row -= count;
-		s->range.end.row -= count;
-
-		/* Scenarios do not allow cross sheet references. */
-
-		/* FIXME: What if we fell off the end?  */
-
-		g_free (s->cell_sel_str);
-		s->cell_sel_str = g_strdup (range_as_string (&s->range));
-	}
-}
-
-void
-scenarios_delete_rows (GList *list, int row, int count)
-{
-	while (list != NULL) {
-		delete_rows (list->data, row, count);
-		list = list->next;
-	}
-}
-
-static void
-move_range (scenario_t *s, Sheet const *sheet, GnmRange const *origin,
-	    int col_offset, int row_offset)
-{
-	/* FIXME when multiple ranges are supported. */
-	if (range_equal (&s->range, origin)) {
-		range_translate (&s->range, sheet, col_offset, row_offset);
-		/* FIXME: What if we fell off the end?  */
-		g_free (s->cell_sel_str);
-		s->cell_sel_str = g_strdup (range_as_string (&s->range));
-	}
-}
-
-void
-scenarios_move_range (GList *list, Sheet const *sheet, const GnmRange *origin,
-		      int col_offset, int row_offset)
-{
-	for ( ; list != NULL ; list = list->next)
-		move_range (list->data, sheet, origin, col_offset, row_offset);
-}
-
 /* Scenario Manager: Ok/Cancel buttons************************************/
 
 /* Ok button pressed. */
@@ -511,7 +385,7 @@ scenario_manager_ok (Sheet *sheet)
 
 	/* Update scenarios (free the deleted ones). */
 	for (cur = scenarios; cur != NULL; cur = cur->next) {
-		scenario_t *s = cur->data;
+		GnmScenario *s = cur->data;
 
 		if (s->marked_deleted)
 			scenario_free (s);
@@ -529,7 +403,7 @@ void
 scenario_recover_all (GList *scenarios)
 {
 	while (scenarios) {
-		scenario_t *s = scenarios->data;
+		GnmScenario *s = scenarios->data;
 
 		s->marked_deleted = FALSE;
 		scenarios = scenarios->next;
@@ -625,7 +499,7 @@ scenario_summary_res_cells (WorkbookControl *wbc, GSList *results,
 		range_init_value (&r, (GnmValue *) results->data);
 		for (i = r.start.col; i <= r.end.col; i++)
 			for (j = r.start.row; j <= r.end.row; j++) {
-				scenario_t *ov = NULL;
+				GnmScenario *ov = NULL;
 				GnmCell    *cell;
 				GList      *cur;
 
@@ -645,7 +519,7 @@ scenario_summary_res_cells (WorkbookControl *wbc, GSList *results,
 				col = 2;
 				for (cur = cb->sheet->scenarios; cur != NULL;
 				     cur = cur->next) {
-					scenario_t *s = cur->data;
+					GnmScenario *s = cur->data;
 
 					ov = scenario_show (wbc, s, ov, &dao);
 
@@ -698,7 +572,7 @@ scenario_summary (WorkbookControl *wbc,
 	cb.results = results;
 	for (cb.col = 0, cur = scenarios; cur != NULL; cb.col++,
 		     cur = cur->next) {
-		scenario_t *s = cur->data;
+		GnmScenario *s = cur->data;
 
 		/* Scenario name. */
 		dao_set_cell (&cb.dao, 2 + cb.col, 1, s->name);
diff --git a/src/tools/scenarios.h b/src/tools/scenarios.h
index 0afb3e2..e604019 100644
--- a/src/tools/scenarios.h
+++ b/src/tools/scenarios.h
@@ -4,7 +4,7 @@
 #include <gnumeric.h>
 #include <tools/dao.h>
 
-typedef struct _scenario_t {
+typedef struct GnmScenario_ {
         Sheet *sheet;
         gchar *name;
 
@@ -15,41 +15,34 @@ typedef struct _scenario_t {
         gchar *cell_sel_str;
 
         gboolean marked_deleted;
-} scenario_t;
+} GnmScenario;
 
 typedef struct _scenario_cmd_t {
-        scenario_t *redo;
-        scenario_t *undo;
+        GnmScenario *redo;
+        GnmScenario *undo;
 } scenario_cmd_t;
 
-scenario_t *scenario_by_name      (GList *scenarios, const gchar *name,
+GnmScenario *scenario_by_name      (GList *scenarios, const gchar *name,
 				   gboolean *all_deleted);
-void        scenario_free         (scenario_t *s);
+void        scenario_free         (GnmScenario *s);
 
 GList      *scenarios_dup	  (GList *list, Sheet *dst);
 void        scenarios_free	  (GList *list);
-void        scenarios_insert_rows (GList *list, int row, int count);
-void        scenarios_insert_cols (GList *list, int row, int count);
-void        scenarios_delete_rows (GList *list, int row, int count);
-void        scenarios_delete_cols (GList *list, int row, int count);
-void        scenarios_move_range  (GList *list,
-				   Sheet const *sheet, GnmRange const *origin,
-				   int col_offset, int row_offset);
 
 void        scenario_manager_ok   (Sheet *sheet);
-scenario_t *scenario_show         (WorkbookControl        *wbc,
-				   scenario_t             *scenario,
-				   scenario_t             *old_values,
+GnmScenario *scenario_show         (WorkbookControl        *wbc,
+				   GnmScenario             *scenario,
+				   GnmScenario             *old_values,
 				   data_analysis_output_t *dao);
 gboolean    scenario_add_new      (gchar const *name,
 				   GnmValue *changing_cells,
 				   gchar const *cell_sel_str,
 				   gchar const *comment,
-				   Sheet *sheet, scenario_t **new_scenario);
-void        scenario_add          (Sheet *sheet, scenario_t *scenario);
+				   Sheet *sheet, GnmScenario **new_scenario);
+void        scenario_add          (Sheet *sheet, GnmScenario *scenario);
 gboolean    scenario_mark_deleted (GList *scenarios, gchar *name);
 GList      *scenario_delete       (GList *scenarios, gchar *name);
-scenario_t *scenario_copy         (scenario_t *s, Sheet *new_sheet);
+GnmScenario *scenario_copy         (GnmScenario *s, Sheet *new_sheet);
 void        scenario_summary      (WorkbookControl        *wbc,
 				   Sheet                  *sheet,
 				   GSList                 *results,
diff --git a/src/xml-sax-write.c b/src/xml-sax-write.c
index 359d2bd..bbab272 100644
--- a/src/xml-sax-write.c
+++ b/src/xml-sax-write.c
@@ -1053,7 +1053,7 @@ xml_write_scenarios (GnmOutputXML *state)
 	gsf_xml_out_start_element (state->output, GNM "Scenarios");
 
 	for (ptr = state->sheet->scenarios ; ptr != NULL ; ptr = ptr->next) {
-		scenario_t const *s = (scenario_t const *)ptr->data;
+		GnmScenario const *s = (GnmScenario const *)ptr->data;
 #if 0
 		int       i, cols, rows;
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]