r15337 - gnucash/branches/sx-cleanup/src - Add the hidden/non-editable 'i' variable to the instances. Filter non-editable variables from the since-last-run value tree.
Joshua Sled
jsled at cvs.gnucash.org
Thu Jan 11 18:20:37 EST 2007
Author: jsled
Date: 2007-01-11 18:20:36 -0500 (Thu, 11 Jan 2007)
New Revision: 15337
Trac: http://svn.gnucash.org/trac/changeset/15337
Modified:
gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.c
gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.h
gnucash/branches/sx-cleanup/src/gnome/dialog-sx-since-last-run.c
Log:
Add the hidden/non-editable 'i' variable to the instances. Filter non-editable variables from the since-last-run value tree.
Modified: gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.c
===================================================================
--- gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.c 2007-01-11 22:16:23 UTC (rev 15336)
+++ gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.c 2007-01-11 23:20:36 UTC (rev 15337)
@@ -34,8 +34,8 @@
#include "gnc-event.h"
#include "gnc-exp-parser.h"
#include "gnc-glib-utils.h"
+#include "gnc-ui-util.h"
#include "gnc-sx-instance-model.h"
-#include "gnc-ui-util.h"
#include "qof.h"
static GObjectClass *parent_class = NULL;
@@ -132,6 +132,15 @@
return var;
}
+GncSxVariable*
+gnc_sx_variable_new_full(gchar *name, gnc_numeric value, gboolean editable)
+{
+ GncSxVariable *var = gnc_sx_variable_new(name);
+ var->value = value;
+ var->editable = editable;
+ return var;
+}
+
static gint
_get_vars_helper(Transaction *txn, void *var_hash_data)
{
@@ -264,12 +273,23 @@
sxsl_get_sx_vars(parent->sx, parent->variable_names);
g_hash_table_foreach(parent->variable_names, (GHFunc)_wipe_parsed_sx_var, NULL);
parent->variable_names_parsed = TRUE;
-
- // @@fixme: add sequence_num as `i`, non-editable
}
rtn->variable_bindings = g_hash_table_new(g_str_hash, g_str_equal);
g_hash_table_foreach(parent->variable_names, _clone_sx_var_hash_entry, rtn->variable_bindings);
+
+ {
+ int instance_i_value;
+ gnc_numeric i_num;
+ GncSxVariable *as_var;
+
+ instance_i_value = gnc_sx_get_instance_count(rtn->parent->sx, rtn->temporal_state);
+ i_num = gnc_numeric_create(instance_i_value, 1);
+ as_var = gnc_sx_variable_new_full("i", i_num, FALSE);
+
+ g_hash_table_insert(rtn->variable_bindings, "i", as_var);
+ }
+
return rtn;
}
@@ -285,8 +305,8 @@
{
GList *vars = NULL;
g_hash_table_foreach(inst->variable_bindings, _build_list_from_hash_elts, &vars);
-
// @@fixme sort by name
+ // @@fixme make sure the returned list is freed by callers.
return vars;
}
@@ -418,19 +438,27 @@
}
static void
+gnc_sx_instance_free(GncSxInstance *instance)
+{
+ // @fixme:
+ // variable_bindings elts + map
+ // temporal_state (iff not postponed?)
+
+ g_free(instance);
+}
+
+static void
gnc_sx_instances_free(GncSxInstances *instances)
{
GList *instance_iter;
+ // @fixme:
+ // variable_names
+ // sx = null
+
for (instance_iter = instances->list; instance_iter != NULL; instance_iter = instance_iter->next)
{
GncSxInstance *inst = (GncSxInstance*)instance_iter->data;
- // gnc_sx_instance_free(inst); {...
-
- // @fixme:
- // variable_bindings elts + map
- // temporal_state (iff not postponed?)
- // object itself
- g_free(inst);
+ gnc_sx_instance_free(inst);
}
g_list_free(instances->list);
instances->list = NULL;
Modified: gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.h
===================================================================
--- gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.h 2007-01-11 22:16:23 UTC (rev 15336)
+++ gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.h 2007-01-11 23:20:36 UTC (rev 15337)
@@ -26,6 +26,7 @@
#include "config.h"
#include <glib.h>
#include <glib-object.h>
+#include "gnc-numeric.h"
#include "SchedXaction.h"
G_BEGIN_DECLS
@@ -46,9 +47,9 @@
gint qof_event_handler_id;
/* signals */
- /* void (*added)(GncSxInstance *inst); // gpointer user_data */
- /* void (*updated)(); // gpointer user_data */
- /* void (*removing)(GncSxInstance *inst); // gpointer user_data */
+ /* void (*added)(SchedXaction *sx); // gpointer user_data */
+ /* void (*updated)(SchedXaction *sx); // gpointer user_data */
+ /* void (*removing)(SchedXaction *sx); // gpointer user_data */
/* public */
GDate range_end;
@@ -73,7 +74,7 @@
GDate next_instance_date;
/** GList<GncSxInstance*> **/
- GList *list; // @fixme: s/list/?/
+ GList *list; /* @fixme: s/list/?/ */
} GncSxInstances;
typedef enum
@@ -126,6 +127,8 @@
**/
GHashTable* gnc_sx_instance_get_variables_for_parser(GHashTable *instance_var_hash);
+GncSxVariable* gnc_sx_variable_new_full(gchar *name, gnc_numeric value, gboolean editable);
+
G_END_DECLS
#endif // _GNC_SX_INSTANCE_MODEL_H
Modified: gnucash/branches/sx-cleanup/src/gnome/dialog-sx-since-last-run.c
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome/dialog-sx-since-last-run.c 2007-01-11 22:16:23 UTC (rev 15336)
+++ gnucash/branches/sx-cleanup/src/gnome/dialog-sx-since-last-run.c 2007-01-11 23:20:36 UTC (rev 15337)
@@ -486,6 +486,10 @@
{
GncSxVariable *var = (GncSxVariable*)var_iter->data;
GString *tmp_str;
+
+ if (!var->editable)
+ continue;
+
if (gnc_numeric_check(var->value) == GNC_ERROR_OK)
{
_var_numeric_to_string(&var->value, &tmp_str);
@@ -606,7 +610,19 @@
if (var_loc != NULL)
{
- *var_loc = (GncSxVariable*)g_list_nth_data(variables, variable_index);
+ // *var_loc = (GncSxVariable*)g_list_nth_data(variables, variable_index);
+ GList *list_iter = variables;
+ for (; list_iter != NULL; list_iter = list_iter->next)
+ {
+ GncSxVariable *var = (GncSxVariable*)list_iter->data;
+ if (!var->editable)
+ continue;
+ if (variable_index-- == 0)
+ {
+ *var_loc = var;
+ break;
+ }
+ }
}
g_list_free(variables);
@@ -685,6 +701,25 @@
}
}
+/**
+ * Special-case list indexing that only refers to "editable" variables. :(
+ **/
+static gint
+_variable_list_index(GList *variables, GncSxVariable *variable)
+{
+ gint index = 0;
+ for (; variables != NULL; variables = variables->next)
+ {
+ GncSxVariable *var = (GncSxVariable*)variables->data;
+ if (!var->editable)
+ continue;
+ if (variable == var)
+ return index;
+ index++;
+ }
+ return -1;
+}
+
static GtkTreePath*
_get_path_for_variable(GncSxSlrTreeModelAdapter *model, GncSxInstance *instance, GncSxVariable *variable)
{
@@ -699,7 +734,7 @@
if (indices[1] == -1)
return NULL;
variables = gnc_sx_instance_get_variables(instance);
- indices[2] = g_list_index(variables, variable);
+ indices[2] = _variable_list_index(variables, variable);
g_list_free(variables);
if (indices[2] == -1)
return NULL;
More information about the gnucash-changes
mailing list