mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Merge Richard Cohen's 'declare-type-app-utils' into stable.
This commit is contained in:
commit
583446ade5
@ -149,7 +149,7 @@ gsidca_get_contained(GncDenseCalModel *model)
|
||||
GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(model);
|
||||
//"removing return gnc_g_list_map(instances->sxes, sx_to_tag, null);
|
||||
GList *list = NULL, *sxes;
|
||||
for (sxes = adapter->instances->sx_instance_list; sxes != NULL; sxes = sxes->next)
|
||||
for (sxes = gnc_sx_instance_model_get_sx_instances_list (adapter->instances); sxes != NULL; sxes = sxes->next)
|
||||
{
|
||||
GncSxInstances *sx_instances = (GncSxInstances*)sxes->data;
|
||||
if (xaccSchedXactionGetEnabled(sx_instances->sx))
|
||||
@ -164,7 +164,7 @@ gsidca_get_name(GncDenseCalModel *model, guint tag)
|
||||
{
|
||||
GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(model);
|
||||
GncSxInstances *insts
|
||||
= (GncSxInstances*)g_list_find_custom(adapter->instances->sx_instance_list, GUINT_TO_POINTER(tag), gsidca_find_sx_with_tag)->data;
|
||||
= (GncSxInstances*)g_list_find_custom(gnc_sx_instance_model_get_sx_instances_list (adapter->instances), GUINT_TO_POINTER(tag), gsidca_find_sx_with_tag)->data;
|
||||
if (insts == NULL)
|
||||
return NULL;
|
||||
return xaccSchedXactionGetName(insts->sx);
|
||||
@ -178,7 +178,7 @@ gsidca_get_info(GncDenseCalModel *model, guint tag)
|
||||
GList *schedule;
|
||||
gchar *schedule_str;
|
||||
GncSxInstances *insts
|
||||
= (GncSxInstances*)g_list_find_custom(adapter->instances->sx_instance_list, GUINT_TO_POINTER(tag), gsidca_find_sx_with_tag)->data;
|
||||
= (GncSxInstances*)g_list_find_custom(gnc_sx_instance_model_get_sx_instances_list(adapter->instances), GUINT_TO_POINTER(tag), gsidca_find_sx_with_tag)->data;
|
||||
if (insts == NULL)
|
||||
return NULL;
|
||||
schedule = gnc_sx_get_schedule(insts->sx);
|
||||
@ -192,7 +192,7 @@ gsidca_get_instance_count(GncDenseCalModel *model, guint tag)
|
||||
GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(model);
|
||||
// g_list_find(instances->sxes, {sx_to_tag, tag}).length();
|
||||
GncSxInstances *insts
|
||||
= (GncSxInstances*)g_list_find_custom(adapter->instances->sx_instance_list, GUINT_TO_POINTER(tag), gsidca_find_sx_with_tag)->data;
|
||||
= (GncSxInstances*)g_list_find_custom(gnc_sx_instance_model_get_sx_instances_list(adapter->instances), GUINT_TO_POINTER(tag), gsidca_find_sx_with_tag)->data;
|
||||
if (insts == NULL)
|
||||
return 0;
|
||||
return g_list_length(insts->instance_list);
|
||||
@ -204,7 +204,7 @@ gsidca_get_instance(GncDenseCalModel *model, guint tag, gint instance_index, GDa
|
||||
GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(model);
|
||||
GncSxInstance *inst;
|
||||
GncSxInstances *insts
|
||||
= (GncSxInstances*)g_list_find_custom(adapter->instances->sx_instance_list, GUINT_TO_POINTER(tag), gsidca_find_sx_with_tag)->data;
|
||||
= (GncSxInstances*)g_list_find_custom(gnc_sx_instance_model_get_sx_instances_list(adapter->instances), GUINT_TO_POINTER(tag), gsidca_find_sx_with_tag)->data;
|
||||
if (insts == NULL)
|
||||
return;
|
||||
inst = (GncSxInstance*)g_list_nth_data(insts->instance_list, instance_index);
|
||||
|
@ -465,7 +465,7 @@ gsltma_populate_tree_store (GncSxListTreeModelAdapter *model)
|
||||
GtkTreeIter iter;
|
||||
GList *list;
|
||||
|
||||
for (list = model->instances->sx_instance_list; list != NULL; list = list->next)
|
||||
for (list = gnc_sx_instance_model_get_sx_instances_list (model->instances); list != NULL; list = list->next)
|
||||
{
|
||||
GncSxInstances *instances = (GncSxInstances*)list->data;
|
||||
gchar *frequency_str;
|
||||
@ -553,7 +553,7 @@ gsltma_get_sx_instances_from_orig_iter (GncSxListTreeModelAdapter *model, GtkTre
|
||||
index = indices[0];
|
||||
|
||||
gtk_tree_path_free (path);
|
||||
return (GncSxInstances*)g_list_nth_data (model->instances->sx_instance_list, index);
|
||||
return (GncSxInstances*)g_list_nth_data (gnc_sx_instance_model_get_sx_instances_list (model->instances), index);
|
||||
}
|
||||
|
||||
GncSxInstances*
|
||||
|
@ -411,7 +411,7 @@ gsslrtma_populate_tree_store (GncSxSlrTreeModelAdapter *model)
|
||||
GList *sx_iter;
|
||||
int instances_index = -1;
|
||||
|
||||
for (sx_iter = model->instances->sx_instance_list; sx_iter != NULL; sx_iter = sx_iter->next)
|
||||
for (sx_iter = gnc_sx_instance_model_get_sx_instances_list (model->instances); sx_iter != NULL; sx_iter = sx_iter->next)
|
||||
{
|
||||
GncSxInstances *instances = (GncSxInstances*)sx_iter->data;
|
||||
char last_occur_date_buf[MAX_DATE_LENGTH+1];
|
||||
@ -549,7 +549,7 @@ _gnc_sx_slr_tree_model_adapter_get_sx_instances (GncSxSlrTreeModelAdapter *model
|
||||
index = indices[0];
|
||||
gtk_tree_path_free (path);
|
||||
|
||||
return (GncSxInstances*)g_list_nth_data (model->instances->sx_instance_list, index);
|
||||
return (GncSxInstances*)g_list_nth_data (gnc_sx_instance_model_get_sx_instances_list (model->instances), index);
|
||||
}
|
||||
|
||||
GncSxInstance*
|
||||
@ -575,7 +575,7 @@ _gnc_sx_slr_model_get_instance (GncSxSlrTreeModelAdapter *model, GtkTreeIter *it
|
||||
instance_index = indices[1];
|
||||
gtk_tree_path_free (path);
|
||||
|
||||
instances = (GncSxInstances*)g_list_nth_data (model->instances->sx_instance_list, instances_index);
|
||||
instances = (GncSxInstances*)g_list_nth_data (gnc_sx_instance_model_get_sx_instances_list (model->instances), instances_index);
|
||||
if (instance_index < 0 || instance_index >= g_list_length (instances->instance_list))
|
||||
{
|
||||
return NULL;
|
||||
@ -667,7 +667,7 @@ _get_path_for_variable (GncSxSlrTreeModelAdapter *model, GncSxInstance *instance
|
||||
int indices[3];
|
||||
GtkTreePath *path;
|
||||
|
||||
indices[0] = g_list_index (model->instances->sx_instance_list, instance->parent);
|
||||
indices[0] = g_list_index (gnc_sx_instance_model_get_sx_instances_list (model->instances), instance->parent);
|
||||
if (indices[0] == -1)
|
||||
return NULL;
|
||||
indices[1] = g_list_index (instance->parent->instance_list, instance);
|
||||
@ -706,7 +706,7 @@ gsslrtma_removing_cb (GncSxInstanceModel *instances, SchedXaction *to_remove_sx,
|
||||
GList *iter;
|
||||
int index = 0;
|
||||
// get index, create path, remove
|
||||
for (iter = instances->sx_instance_list; iter != NULL; iter = iter->next, index++)
|
||||
for (iter = gnc_sx_instance_model_get_sx_instances_list (instances); iter != NULL; iter = iter->next, index++)
|
||||
{
|
||||
GncSxInstances *instances = (GncSxInstances*)iter->data;
|
||||
if (instances->sx == to_remove_sx)
|
||||
|
@ -72,6 +72,18 @@ typedef struct _SxTxnCreationData
|
||||
GList **creation_errors;
|
||||
} SxTxnCreationData;
|
||||
|
||||
struct _GncSxInstanceModel
|
||||
{
|
||||
GObject parent;
|
||||
gboolean disposed;
|
||||
|
||||
gint qof_event_handler_id;
|
||||
|
||||
GDate range_end;
|
||||
gboolean include_disabled;
|
||||
GList *sx_instance_list; /* <GncSxInstances*> */
|
||||
};
|
||||
|
||||
static GncSxInstanceModel* gnc_sx_instance_model_new(void);
|
||||
|
||||
static GncSxInstance* gnc_sx_instance_new(GncSxInstances *parent, GncSxInstanceState state, GDate *date, void *temporal_state, gint sequence_num);
|
||||
@ -90,6 +102,14 @@ typedef struct
|
||||
gnc_numeric amount;
|
||||
} ScrubItem;
|
||||
|
||||
enum
|
||||
{
|
||||
REMOVING, UPDATED, ADDED,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static void
|
||||
scrub_sx_split_numeric (Split* split, gboolean is_credit, GList **changes)
|
||||
{
|
||||
@ -670,7 +690,7 @@ gnc_sx_instance_model_class_init (GncSxInstanceModelClass *klass)
|
||||
object_class->dispose = gnc_sx_instance_model_dispose;
|
||||
object_class->finalize = gnc_sx_instance_model_finalize;
|
||||
|
||||
klass->removing_signal_id =
|
||||
signals[REMOVING] =
|
||||
g_signal_new("removing",
|
||||
GNC_TYPE_SX_INSTANCE_MODEL,
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
@ -682,7 +702,7 @@ gnc_sx_instance_model_class_init (GncSxInstanceModelClass *klass)
|
||||
1,
|
||||
G_TYPE_POINTER);
|
||||
|
||||
klass->updated_signal_id =
|
||||
signals[UPDATED] =
|
||||
g_signal_new("updated",
|
||||
GNC_TYPE_SX_INSTANCE_MODEL,
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
@ -694,7 +714,7 @@ gnc_sx_instance_model_class_init (GncSxInstanceModelClass *klass)
|
||||
1,
|
||||
G_TYPE_POINTER);
|
||||
|
||||
klass->added_signal_id =
|
||||
signals[ADDED] =
|
||||
g_signal_new("added",
|
||||
GNC_TYPE_SX_INSTANCE_MODEL,
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
@ -1898,3 +1918,8 @@ GHashTable* gnc_sx_all_instantiate_cashflow_all(GDate range_start, GDate range_e
|
||||
result_map, NULL);
|
||||
return result_map;
|
||||
}
|
||||
|
||||
GList *gnc_sx_instance_model_get_sx_instances_list (GncSxInstanceModel *model)
|
||||
{
|
||||
return model->sx_instance_list;
|
||||
}
|
||||
|
@ -35,39 +35,7 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GNC_TYPE_SX_INSTANCE_MODEL (gnc_sx_instance_model_get_type ())
|
||||
#define GNC_SX_INSTANCE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_SX_INSTANCE_MODEL, GncSxInstanceModel))
|
||||
#define GNC_SX_INSTANCE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_SX_INSTANCE_MODEL, GncSxInstanceModelClass))
|
||||
#define GNC_IS_SX_INSTANCE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_SX_INSTANCE_MODEL))
|
||||
#define GNC_IS_SX_INSTANCE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_SX_INSTANCE_MODEL))
|
||||
#define GNC_SX_INSTANCE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_SX_INSTANCE_MODEL, GncSxInstanceModelClass))
|
||||
|
||||
typedef struct _GncSxInstanceModel
|
||||
{
|
||||
GObject parent;
|
||||
gboolean disposed;
|
||||
|
||||
/* private */
|
||||
gint qof_event_handler_id;
|
||||
|
||||
/* signals */
|
||||
/* 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;
|
||||
gboolean include_disabled;
|
||||
GList *sx_instance_list; /* <GncSxInstances*> */
|
||||
} GncSxInstanceModel;
|
||||
|
||||
typedef struct _GncSxInstanceModelClass
|
||||
{
|
||||
GObjectClass parent;
|
||||
|
||||
guint removing_signal_id;
|
||||
guint updated_signal_id;
|
||||
guint added_signal_id;
|
||||
} GncSxInstanceModelClass;
|
||||
G_DECLARE_FINAL_TYPE (GncSxInstanceModel, gnc_sx_instance_model, GNC, SX_INSTANCE_MODEL, GObject)
|
||||
|
||||
typedef struct _GncSxInstances
|
||||
{
|
||||
@ -114,8 +82,6 @@ typedef struct _GncSxVariableNeeded
|
||||
GncSxVariable *variable;
|
||||
} GncSxVariableNeeded;
|
||||
|
||||
GType gnc_sx_instance_model_get_type(void);
|
||||
|
||||
/** Shorthand for get_instances(now, FALSE); */
|
||||
GncSxInstanceModel* gnc_sx_get_current_instances(void);
|
||||
|
||||
@ -256,6 +222,13 @@ void gnc_sx_all_instantiate_cashflow(GList *all_sxes,
|
||||
* g_hash_table_destroy. */
|
||||
GHashTable* gnc_sx_all_instantiate_cashflow_all(GDate range_start, GDate range_end);
|
||||
|
||||
/** Returns the list of GncSxInstances in the model
|
||||
* (Each element in the list has type GncSxInstances)
|
||||
*
|
||||
* The returned list is owned by the model
|
||||
*/
|
||||
GList *gnc_sx_instance_model_get_sx_instances_list (GncSxInstanceModel *model);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
|
@ -60,8 +60,8 @@ test_basic()
|
||||
GncSxInstances *insts;
|
||||
GList *iter;
|
||||
|
||||
do_test(g_list_length(model->sx_instance_list) == 1, "1 GncSxInstances");
|
||||
insts = (GncSxInstances*)model->sx_instance_list->data;
|
||||
do_test(g_list_length(gnc_sx_instance_model_get_sx_instances_list(model)) == 1, "1 GncSxInstances");
|
||||
insts = (GncSxInstances*)gnc_sx_instance_model_get_sx_instances_list(model)->data;
|
||||
do_test(g_list_length(insts->instance_list) == 3, "yesterday, today and tomorrow");
|
||||
for (iter = insts->instance_list; iter != NULL; iter = iter->next)
|
||||
{
|
||||
@ -93,7 +93,7 @@ test_empty()
|
||||
|
||||
end = g_date_new_dmy(31, (GDateMonth)12, way_in_the_future_year);
|
||||
model = gnc_sx_get_instances(end, TRUE);
|
||||
do_test(g_list_length(model->sx_instance_list) == 0, "no instances");
|
||||
do_test(g_list_length(gnc_sx_instance_model_get_sx_instances_list(model)) == 0, "no instances");
|
||||
g_object_unref(G_OBJECT(model));
|
||||
g_date_free(end);
|
||||
success("empty");
|
||||
@ -128,8 +128,8 @@ test_once()
|
||||
|
||||
model = gnc_sx_get_instances(end, TRUE);
|
||||
|
||||
do_test(g_list_length(model->sx_instance_list) == 1, "1 instances");
|
||||
instances = (GncSxInstances*)model->sx_instance_list->data;
|
||||
do_test(g_list_length(gnc_sx_instance_model_get_sx_instances_list(model)) == 1, "1 instances");
|
||||
instances = (GncSxInstances*)gnc_sx_instance_model_get_sx_instances_list(model)->data;
|
||||
do_test(g_list_length(instances->instance_list) == 1, "1 instance");
|
||||
instance = (GncSxInstance*)instances->instance_list->data;
|
||||
do_test(g_date_compare(when, &instances->next_instance_date) == 0, "next instance is expected");
|
||||
@ -165,8 +165,8 @@ test_state_changes()
|
||||
foo = add_daily_sx("foo", start, NULL, NULL);
|
||||
model = gnc_sx_get_instances(end, TRUE);
|
||||
|
||||
do_test(g_list_length(model->sx_instance_list) == 1, "one sx");
|
||||
insts = (GncSxInstances*)g_list_nth_data(model->sx_instance_list, 0);
|
||||
do_test(g_list_length(gnc_sx_instance_model_get_sx_instances_list(model)) == 1, "one sx");
|
||||
insts = (GncSxInstances*)g_list_nth_data(gnc_sx_instance_model_get_sx_instances_list(model), 0);
|
||||
do_test(g_list_length(insts->instance_list) == 4, "4 instances");
|
||||
|
||||
inst = _nth_instance(insts, 2);
|
||||
|
Loading…
Reference in New Issue
Block a user