r14527 - gnucash/branches/register-rewrite/src/gnome-utils - Generalize the utility function for getting an iter from a split/trans.

Chris Shoemaker chris at cvs.gnucash.org
Sun Jul 16 20:18:17 EDT 2006


Author: chris
Date: 2006-07-16 20:18:13 -0400 (Sun, 16 Jul 2006)
New Revision: 14527
Trac: http://svn.gnucash.org/trac/changeset/14527

Modified:
   gnucash/branches/register-rewrite/src/gnome-utils/gnc-tree-model-transaction.c
   gnucash/branches/register-rewrite/src/gnome-utils/gnc-tree-model-transaction.h
Log:
   Generalize the utility function for getting an iter from a split/trans.
   Provide a function for getting the iter of the blank trans.
   Delete some cruft.


Modified: gnucash/branches/register-rewrite/src/gnome-utils/gnc-tree-model-transaction.c
===================================================================
--- gnucash/branches/register-rewrite/src/gnome-utils/gnc-tree-model-transaction.c	2006-07-17 00:04:54 UTC (rev 14526)
+++ gnucash/branches/register-rewrite/src/gnome-utils/gnc-tree-model-transaction.c	2006-07-17 00:18:13 UTC (rev 14527)
@@ -910,10 +910,10 @@
     if (depth == 2) {
         if (gtk_tree_path_up(path) && gnc_tree_model_transaction_get_iter(
                 GTK_TREE_MODEL(model), &iter, path)) {
-            //gtk_tree_model_row_changed(GTK_TREE_MODEL(model), path, &iter);
+            gtk_tree_model_row_changed(GTK_TREE_MODEL(model), path, &iter);
             tnode = iter.user_data2;
             /* Assumption: When the blank split is removed from the blank
-               trans, it's always the last child of the blank trans. */
+               trans, it's always the last child of the blank trans. */ 
             if (IS_BLANK_TRANS(&iter) && tnode->data == model->priv->btrans) {
                 increment_stamp(model);
 
@@ -1036,9 +1036,9 @@
     g_return_val_if_fail(VALID_ITER(model, iter), FALSE);
 
     if (is_split)
-        *is_split = IS_SPLIT(iter);
+        *is_split = !!IS_SPLIT(iter);
     if (is_blank)
-        *is_blank = IS_BLANK(iter);
+        *is_blank = !!IS_BLANK(iter);
 
     if (trans) {
         node = iter->user_data2;
@@ -1134,62 +1134,55 @@
     }
 }
 
-static gboolean
-get_iter_from_split (GncTreeModelTransaction *model, Split *split,
-                     GtkTreeIter *iter)
+#define get_iter gnc_tree_model_transaction_get_iter_from_trans_and_split
+gboolean
+gnc_tree_model_transaction_get_iter_from_trans_and_split(
+    GncTreeModelTransaction *model, Transaction *trans, Split *split, 
+    GtkTreeIter *iter)
 {
     GncTreeModelTransactionPrivate *priv;
-    GList *tnode, *snode, *slist;
-    Transaction *trans;
-    gint flags;
+    GList *tnode, *snode = NULL;
+    gint flags = 0;
 
-    g_return_val_if_fail(GNC_IS_TREE_MODEL_TRANSACTION (model), FALSE);
-    g_return_val_if_fail(split && iter, FALSE);
+    g_return_val_if_fail(GNC_IS_TREE_MODEL_TRANSACTION(model), FALSE);
+    g_return_val_if_fail(VALID_ITER(model, iter), FALSE);
 
     priv = model->priv;
-    if (priv->book != xaccSplitGetBook(split)) return FALSE;
+    if (split && !trans) trans = xaccSplitGetParent(split);
 
-    trans = xaccSplitGetParent(split);
+    if (trans && priv->book != xaccTransGetBook(trans)) return FALSE;
+    if (split && priv->book != xaccSplitGetBook(split)) return FALSE;    
+    if (split && !xaccTransStillHasSplit(trans, split)) return FALSE;
+
     tnode = g_list_find(priv->tlist, trans);
     if (!tnode) return FALSE;
 
-    if (!xaccTransStillHasSplit(trans, split)) return FALSE;
+    if (split) {
+        GList *slist = xaccTransGetSplitList(trans);
+        snode = g_list_find(slist, split);
+        flags |= SPLIT;
+        if (!snode && split == (Split *) ((GList *)priv->bsplit_node)->data) {
+            snode = priv->bsplit_node;
+            flags |= BLANK;
+        }
+        if (!snode) return FALSE;
+    }
 
-    slist = xaccTransGetSplitList(trans);
-    snode = g_list_find(slist, split);
-    flags = SPLIT;
-    if (!snode && split == (Split *) ((GList *)priv->bsplit_node)->data) {
-        snode = priv->bsplit_node;
+    if (trans == priv->btrans)
         flags |= BLANK;
-    }
-    if (!snode) return FALSE;
 
     *iter = make_iter(model, flags, tnode, snode);
     return TRUE;
 }
 
-gboolean
-gnc_tree_model_transaction_get_iter_from_trans(
-    GncTreeModelTransaction *model, Transaction *trans, GtkTreeIter *iter)
+gboolean 
+gnc_tree_model_transaction_get_blank_trans_iter(GncTreeModelTransaction *model,
+                                                GtkTreeIter *iter)
 {
-    GncTreeModelTransactionPrivate *priv;
-    GList *tnode;
-    gint flags = 0;
+    if (!iter) return FALSE;
 
     g_return_val_if_fail(GNC_IS_TREE_MODEL_TRANSACTION(model), FALSE);
-    g_return_val_if_fail(trans && iter, FALSE);
-
-    priv = model->priv;
-    if (priv->book != xaccTransGetBook(trans)) return FALSE;
-
-    tnode = g_list_find(priv->tlist, trans);
-    if (!tnode) return FALSE;
-
-    if (trans == priv->btrans)
-        flags |= BLANK;
-
-    *iter = make_iter(model, flags, tnode, NULL);
-    return TRUE;
+    return get_iter(model, model->priv->btrans, NULL, iter);
 }
 
 /* Returns just the path to the transaction if idx_of_split is -1. */
@@ -1238,7 +1231,7 @@
     GtkTreeIter iter;
     GtkTreePath *path;
     Transaction *trans;
-    Split *split;
+    Split *split = NULL;
     QofIdType type;
     const gchar *name;
     GList *tnode;
@@ -1255,7 +1248,7 @@
 
         switch (event_type) {
         case QOF_EVENT_MODIFY:
-            if (get_iter_from_split(model, split, &iter)) {
+            if (get_iter(model, NULL, split, &iter)) {
                 DEBUG("change split %p (%s)", split, name);
                 changed_row_at(model, &iter);
             }
@@ -1278,7 +1271,7 @@
             if (split == priv->bsplit) break;
 
             /* Tell the filters/views where the new row was added. */
-            if (get_iter_from_split(model, split, &iter)) {
+            if (get_iter(model, trans, split, &iter)) {
                 DEBUG("add split %p (%s)", split, name);
                 insert_row_at(model, &iter);
             }
@@ -1306,8 +1299,7 @@
                 insert_row_at(model, &iter);
             }
 
-            if (gnc_tree_model_transaction_get_iter_from_trans(
-                    model, trans, &iter)) {
+            if (get_iter(model, trans, NULL, &iter)) {
                 DEBUG("change trans %p (%s)", trans, name);
                 changed_row_at(model, &iter);
             }
@@ -1320,8 +1312,7 @@
 
                 iter = make_iter(model, BLANK, tnode, NULL);
                 changed_row_at(model, &iter);
-            } else if (gnc_tree_model_transaction_get_iter_from_trans(
-                           model, trans, &iter)) {
+            } else if (get_iter(model, trans, NULL, &iter)) {
                 delete_row_at(model, &iter);
                 DEBUG("destroy trans %p (%s)", trans, name);
             }

Modified: gnucash/branches/register-rewrite/src/gnome-utils/gnc-tree-model-transaction.h
===================================================================
--- gnucash/branches/register-rewrite/src/gnome-utils/gnc-tree-model-transaction.h	2006-07-17 00:04:54 UTC (rev 14526)
+++ gnucash/branches/register-rewrite/src/gnome-utils/gnc-tree-model-transaction.h	2006-07-17 00:18:13 UTC (rev 14527)
@@ -84,70 +84,21 @@
 /** @name Transaction Tree Model Get/Set Functions
   @{ */
 
-#if 0
-/** Convert a model/iter pair to a gnucash split.  This routine should
- *  only be called from an split tree view filter function.  The
- *  model and iter values will be provided as part of the call to the
- *  filter.
- *
- *  @param model A pointer to the split tree model.
- *
- *  @param iter A gtk_tree_iter corresponding to a single split in
- *  the model.
- *
- *  @return A pointer to the corresponding split.
- */
-Transaction *gnc_tree_model_transaction_get_split (
-    GncTreeModelTransaction *model, GtkTreeIter *iter);
-
-
-/** Convert a model/split pair into a gtk_tree_model_iter.  This
- *  routine should only be called from the file
- *  gnc-tree-view-split.c.
- *
- *  @internal
- *
- *  @param model The model that an split belongs to.
- *
- *  @param split The split to convert.
- *
- *  @param iter A pointer to an iter.  This iter will be rewritten to
- *  contain the results of the query.
- *
- *  @return TRUE if the split was found and the iter filled
- *  in. FALSE otherwise.
- */
-gboolean gnc_tree_model_transaction_get_iter_from_trans (
-    GncTreeModelTransaction *model,
-    Transaction *trans,
-    GtkTreeIter *iter);
-
-
-/** Convert a model/split pair into a gtk_tree_model_path.  This
- *  routine should only be called from the file
- *  gnc-tree-view-split.c.
- *
- *  @internal
- *
- *  @param model The model that an split belongs to.
- *
- *  @param split The split to convert.
- *
- *  @return A pointer to a path describing the split.  It is the
- *  responsibility of the caller to free this path when done.
- */
-GtkTreePath *gnc_tree_model_transaction_get_path_from_trans (
+// FALSE if failure
+gboolean 
+gnc_tree_model_transaction_set_blank_split_parent(
     GncTreeModelTransaction *model, Transaction *trans);
-#endif
 
-gboolean gnc_tree_model_transaction_set_blank_split_parent(
-    GncTreeModelTransaction *model, Transaction *trans);
+// FALSE if failure
+gboolean 
+gnc_tree_model_transaction_get_blank_trans_iter(GncTreeModelTransaction *model,
+                                                GtkTreeIter *iter);
 
 Account *
 gnc_tree_model_transaction_get_anchor(GncTreeModelTransaction *model);
 
 gboolean
-gnc_tree_model_transaction_get_split_and_trans (
+gnc_tree_model_transaction_get_split_and_trans(
     GncTreeModelTransaction *model, GtkTreeIter *iter,
     gboolean *is_split, gboolean *is_blank,
     Split **split, Transaction **trans);
@@ -158,9 +109,12 @@
 gint gtmt_sort_by_date(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b,
                        gpointer user_data);
 
+/* If 'trans' is NULL, use split's parent.  If 'split' is NULL, just
+   get the transaction iter. */
 gboolean
-gnc_tree_model_transaction_get_iter_from_trans(
-    GncTreeModelTransaction *model, Transaction *trans, GtkTreeIter *iter);
+gnc_tree_model_transaction_get_iter_from_trans_and_split(
+    GncTreeModelTransaction *model, Transaction *trans, Split *split, 
+    GtkTreeIter *iter);
 
 /** @} */
 



More information about the gnucash-changes mailing list