Convert xaccTransGetSplit() and xaccTransCountSplits() to return the

index and count reflective of any in-progress edit.
   Convert some split iterators from directly using the GList of Splits to 
   using xaccTransGetSplit().


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13487 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Chris Shoemaker
2006-03-05 04:14:38 +00:00
parent 35a8b15f41
commit 84bcf5685b
6 changed files with 53 additions and 50 deletions

View File

@@ -345,6 +345,8 @@ xaccTransScrubCurrencyFromSplits(Transaction *trans)
for (node = xaccTransGetSplitList (trans); node; node = node->next) {
Split *split = node->data;
if (!xaccTransStillHasSplit(trans, split)) continue;
if (gnc_numeric_equal(xaccSplitGetAmount (split),
xaccSplitGetValue (split))) {

View File

@@ -1160,6 +1160,7 @@ get_corr_account_split(const Split *sa, const Split **retval)
current_split = node->data;
if (current_split == sa) continue;
if (!xaccTransStillHasSplit(sa->parent, current_split)) continue;
current_value = xaccSplitGetValue (current_split);
current_value_positive = gnc_numeric_positive_p(current_value);
if ((sa_value_positive && !current_value_positive) ||
@@ -1581,9 +1582,9 @@ xaccSplitMakeStockSplit(Split *s)
Split *
xaccSplitGetOtherSplit (const Split *split)
{
SplitList *node;
int i;
Transaction *trans;
int count;
int count, num_splits;
Split *other = NULL;
KvpValue *sva;
@@ -1602,15 +1603,16 @@ xaccSplitGetOtherSplit (const Split *split)
return s1;
#endif
count = g_list_length (trans->splits);
num_splits = xaccTransCountSplits(trans);
count = num_splits;
sva = kvp_frame_get_slot (split->inst.kvp_data, "lot-split");
if (!sva && (2 != count)) return NULL;
for (node = trans->splits; node; node = node->next)
{
Split *s = node->data;
for (i = 0; i < num_splits; i++) {
Split *s = xaccTransGetSplit(trans, i);
if (s == split) { --count; continue; }
if (kvp_frame_get_slot (s->inst.kvp_data, "lot-split")) { --count; continue; }
if (kvp_frame_get_slot (s->inst.kvp_data, "lot-split"))
{ --count; continue; }
other = s;
}
return (1 == count) ? other : NULL;

View File

@@ -717,8 +717,7 @@ xaccTransGetAccountConvRate(Transaction *txn, Account *acc)
xaccTransGetCurrency(txn)))
return gnc_numeric_create(1, 1);
splits = xaccTransGetSplitList(txn);
for (; splits; splits = splits->next) {
for (splits = txn->splits; splits; splits = splits->next) {
s = splits->data;
if (!xaccTransStillHasSplit(txn, s))
@@ -763,7 +762,7 @@ xaccTransGetAccountBalance (const Transaction *trans,
// Not really the appropriate error value.
g_return_val_if_fail(account && trans, gnc_numeric_error(GNC_ERROR_ARG));
for (node = xaccTransGetSplitList(trans); node; node = node->next)
for (node = trans->splits; node; node = node->next)
{
Split *split = node->data;
@@ -1442,9 +1441,11 @@ xaccTransSetNotes (Transaction *trans, const char *notes)
Split *
xaccTransGetSplit (const Transaction *trans, int i)
{
int j = 0;
if (!trans || i < 0) return NULL;
return g_list_nth_data (trans->splits, i);
FOR_EACH_SPLIT(trans, { if (i == j) return s; j++; });
return NULL;
}
SplitList *
@@ -1456,7 +1457,9 @@ xaccTransGetSplitList (const Transaction *trans)
int
xaccTransCountSplits (const Transaction *trans)
{
return trans ? g_list_length (trans->splits) : 0;
gint i = 0;
FOR_EACH_SPLIT(trans, i++);
return i;
}
const char *

View File

@@ -457,12 +457,10 @@ static Split *
gnc_find_split_in_trans_by_memo (Transaction *trans, const char *memo,
gboolean unit_price)
{
GList *node;
for (node = xaccTransGetSplitList (trans); node; node = node->next)
{
Split *split = node->data;
int i;
Split *split;
while (split = xaccTransGetSplit(trans, i)) {
if (unit_price)
{
gnc_numeric price = xaccSplitGetSharePrice (split);
@@ -472,6 +470,7 @@ gnc_find_split_in_trans_by_memo (Transaction *trans, const char *memo,
if (safe_strcmp (memo, xaccSplitGetMemo (split)) == 0)
return split;
i++;
}
return NULL;
@@ -695,21 +694,20 @@ gnc_split_register_auto_completion (SplitRegister *reg,
if (gnc_split_register_get_default_account (reg) != NULL)
{
Account *default_account;
GList *node;
Split *s;
int i;
default_account = gnc_split_register_get_default_account (reg);
blank_split = NULL;
for (node = xaccTransGetSplitList (trans); node; node = node->next)
{
Split *s = node->data;
while (s = xaccTransGetSplit(trans, i)) {
if (default_account == xaccSplitGetAccount(s))
{
blank_split = s;
info->blank_split_guid = *xaccSplitGetGUID(blank_split);
break;
}
i++;
}
if (blank_split == NULL)

View File

@@ -395,7 +395,8 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
* fill up the quickfill cells. */
if (info->first_pass)
{
GList *node;
Split *s;
int i;
gnc_quickfill_cell_add_completion
((QuickFillCell *)
@@ -413,14 +414,14 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
gnc_table_layout_get_cell (reg->table->layout, NUM_CELL),
xaccTransGetNum (trans));
for (node = xaccTransGetSplitList (trans); node; node = node->next)
{
Split *s = node->data;
i = 0;
while (s = xaccTransGetSplit(trans, i)) {
QuickFillCell *cell;
cell = (QuickFillCell *)
gnc_table_layout_get_cell (reg->table->layout, MEMO_CELL);
gnc_quickfill_cell_add_completion (cell, xaccSplitGetMemo (s));
i++;
}
}

View File

@@ -77,18 +77,13 @@ static gboolean gnc_split_register_auto_calc (SplitRegister *reg,
static int
gnc_trans_split_index (Transaction *trans, Split *split)
{
GList *node;
int i;
Split *s;
int i = 0;
for (i = 0, node = xaccTransGetSplitList (trans); node;
i++, node = node->next)
{
Split *s = node->data;
if (s == split)
return i;
while (s = xaccTransGetSplit(trans, i)) {
if (s == split) return i;
i++;
}
return -1;
}
@@ -1077,6 +1072,8 @@ gnc_split_register_empty_current_trans_except_split (SplitRegister *reg, Split *
Transaction *trans;
GList *splits;
GList *node;
int i = 0;
Split *s;
if ((reg == NULL) || (split == NULL))
return;
@@ -1084,12 +1081,12 @@ gnc_split_register_empty_current_trans_except_split (SplitRegister *reg, Split *
gnc_suspend_gui_refresh ();
trans = xaccSplitGetParent (split);
splits = g_list_copy (xaccTransGetSplitList (trans));
xaccTransBeginEdit (trans);
for (node = splits; node; node = node->next)
if (node->data != split)
xaccSplitDestroy (node->data);
g_list_free (splits);
while (s = xaccTransGetSplit(trans, i)) {
if (s != split)
xaccSplitDestroy(s);
i++;
}
/* This is now the pending transaction */
info = gnc_split_register_get_info (reg);