gnucash stable: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Sun Aug 18 07:50:17 EDT 2024
Updated via https://github.com/Gnucash/gnucash/commit/436889b4 (commit)
via https://github.com/Gnucash/gnucash/commit/48f3842e (commit)
via https://github.com/Gnucash/gnucash/commit/32e0aded (commit)
via https://github.com/Gnucash/gnucash/commit/2902f1de (commit)
via https://github.com/Gnucash/gnucash/commit/6790430e (commit)
from https://github.com/Gnucash/gnucash/commit/00e5c62f (commit)
commit 436889b4555d71f1c8d5d6d6a2380f95075808c7
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Mon Jul 8 12:26:46 2024 +0800
[import-main-matcher.cpp] tidy entry setup
diff --git a/gnucash/import-export/import-main-matcher.cpp b/gnucash/import-export/import-main-matcher.cpp
index 84f795bbde..c7adc11ef4 100644
--- a/gnucash/import-export/import-main-matcher.cpp
+++ b/gnucash/import-export/import-main-matcher.cpp
@@ -970,7 +970,7 @@ typedef struct
{
GtkWidget *entry;
GObject *override_widget;
- bool *can_edit;
+ bool& can_edit;
GHashTable *hash;
const char *initial;
} EntryInfo;
@@ -981,17 +981,17 @@ static void override_widget_clicked (GtkWidget *widget, EntryInfo *entryinfo)
gtk_widget_set_sensitive (entryinfo->entry, true);
gtk_entry_set_text (GTK_ENTRY (entryinfo->entry), "");
gtk_widget_grab_focus (entryinfo->entry);
- *entryinfo->can_edit = true;
+ entryinfo->can_edit = true;
}
static void
-setup_entry (EntryInfo *entryinfo)
+setup_entry (EntryInfo& entryinfo)
{
- bool sensitive = *entryinfo->can_edit;
- GtkWidget *entry = entryinfo->entry;
- GtkWidget *override_widget = GTK_WIDGET (entryinfo->override_widget);
- GHashTable *hash = entryinfo->hash;
- const char *initial = entryinfo->initial;
+ auto sensitive = entryinfo.can_edit;
+ auto entry = entryinfo.entry;
+ auto override_widget = GTK_WIDGET (entryinfo.override_widget);
+ auto hash = entryinfo.hash;
+ auto initial = entryinfo.initial;
gtk_widget_set_sensitive (entry, sensitive);
gtk_widget_set_visible (override_widget, !sensitive);
@@ -1002,7 +1002,7 @@ setup_entry (EntryInfo *entryinfo)
{
gtk_entry_set_text (GTK_ENTRY (entry), _("Click Edit to modify"));
g_signal_connect (override_widget, "clicked", G_CALLBACK (override_widget_clicked),
- entryinfo);
+ &entryinfo);
}
GtkListStore *list = gtk_list_store_new (NUM_COMPLETION_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
@@ -1043,22 +1043,18 @@ input_new_fields (GNCImportMainMatcher *info, RowInfo& rowinfo,
auto split = gnc_import_TransInfo_get_fsplit (rowinfo.get_trans_info ());
std::vector<EntryInfo> entries = {
- { desc_entry, gtk_builder_get_object (builder, "desc_override"), &info->can_edit_desc, info->desc_hash, xaccTransGetDescription (trans) },
- { notes_entry, gtk_builder_get_object (builder, "notes_override"), &info->can_edit_notes, info->notes_hash, xaccTransGetNotes (trans) },
- { memo_entry, gtk_builder_get_object (builder, "memo_override"), &info->can_edit_memo, info->memo_hash, xaccSplitGetMemo (split) },
+ { desc_entry, gtk_builder_get_object (builder, "desc_override"), info->can_edit_desc, info->desc_hash, xaccTransGetDescription (trans) },
+ { notes_entry, gtk_builder_get_object (builder, "notes_override"), info->can_edit_notes, info->notes_hash, xaccTransGetNotes (trans) },
+ { memo_entry, gtk_builder_get_object (builder, "memo_override"), info->can_edit_memo, info->memo_hash, xaccSplitGetMemo (split) },
};
- for (auto& entryinfo : entries)
- setup_entry (&entryinfo);
+ std::for_each (entries.begin(), entries.end(), setup_entry);
/* ensure that an override button doesn't have focus. find the
first available entry and give it focus. */
- for (const auto& entryinfo : entries)
- if (entryinfo.can_edit)
- {
- gtk_widget_grab_focus (entryinfo.entry);
- break;
- }
+ auto it = std::find_if (entries.begin(), entries.end(), [](auto info){ return info.can_edit; });
+ if (it != entries.end())
+ gtk_widget_grab_focus (it->entry);
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (info->main_widget));
commit 48f3842eaa80836cecfe391db20f57cfad2e1eb2
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Tue Jun 4 00:29:43 2024 +0800
[Account.cpp] compare vectors with std::equal in xaccAccountEqual
diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp
index 8a5abc250f..5401b7a6fe 100644
--- a/libgnucash/engine/Account.cpp
+++ b/libgnucash/engine/Account.cpp
@@ -1845,26 +1845,13 @@ xaccAccountEqual(const Account *aa, const Account *ab, gboolean check_guids)
/* no parent; always compare downwards. */
+ if (!std::equal (priv_aa->splits.begin(), priv_aa->splits.end(),
+ priv_ab->splits.begin(), priv_ab->splits.end(),
+ [check_guids](auto sa, auto sb)
+ { return xaccSplitEqual(sa, sb, check_guids, true, false); }))
{
- if (priv_aa->splits.size() != priv_ab->splits.size())
- {
- PWARN ("number of splits differs");
- return false;
- }
-
- for (auto it_a = priv_aa->splits.begin(), it_b = priv_ab->splits.begin();
- it_a != priv_aa->splits.end() && it_b != priv_ab->splits.end();
- ++it_a, ++it_b)
- {
- Split *sa = *it_a;
- Split *sb = *it_b;
-
- if (!xaccSplitEqual(sa, sb, check_guids, TRUE, FALSE))
- {
- PWARN ("splits differ");
- return false;
- }
- }
+ PWARN ("splits differ");
+ return false;
}
if (!xaccAcctChildrenEqual(priv_aa->children, priv_ab->children, check_guids))
commit 32e0adedc697ff7b62bca61baf2dea6b263f04a5
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Tue Jun 18 08:37:28 2024 +0800
[window-reconcile.cpp] better c++
- use xaccAccountGetSplits instead of GList* xaccAccountGetSplitList
- use gnc_account_foreach_descendant with std::function
diff --git a/gnucash/gnome/window-reconcile.cpp b/gnucash/gnome/window-reconcile.cpp
index ffed300629..66f6d651fd 100644
--- a/gnucash/gnome/window-reconcile.cpp
+++ b/gnucash/gnome/window-reconcile.cpp
@@ -2244,66 +2244,45 @@ recn_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
static Account *
find_payment_account(Account *account)
{
- if (account == NULL)
- return NULL;
+ if (account == nullptr)
+ return nullptr;
- GList *list = xaccAccountGetSplitList (account);
- Account *rv = nullptr;
+ const auto& splits = xaccAccountGetSplits (account);
/* Search backwards to find the latest payment */
- for (GList *node = g_list_last (list); !rv && node; node = node->prev)
+ for (auto it = splits.rbegin(); it != splits.rend(); it++)
{
- Transaction *trans;
- GList *n;
-
- auto split = GNC_SPLIT(node->data);
- if (split == NULL)
- continue;
+ auto split = *it;
/* ignore 'purchases' */
if (!gnc_numeric_positive_p (xaccSplitGetAmount(split)))
continue;
- trans = xaccSplitGetParent(split);
- if (trans == NULL)
- continue;
-
- for (n = xaccTransGetSplitList (trans); n; n = n->next)
+ for (auto n = xaccTransGetSplitList (xaccSplitGetParent(split)); n; n = n->next)
{
- GNCAccountType type;
- Account *a;
-
auto s = GNC_SPLIT(n->data);
- if ((s == NULL) || (s == split))
+ if (s == split)
continue;
- a = xaccSplitGetAccount(s);
- if ((a == NULL) || (a == account))
+ auto a = xaccSplitGetAccount(s);
+ if (a == account)
continue;
- type = xaccAccountGetType(a);
- if ((type == ACCT_TYPE_BANK) || (type == ACCT_TYPE_CASH) ||
- (type == ACCT_TYPE_ASSET))
- rv = a;
+ auto type = xaccAccountGetType(a);
+ if (type == ACCT_TYPE_BANK || type == ACCT_TYPE_CASH || type == ACCT_TYPE_ASSET)
+ return a;
}
}
- g_list_free (list);
- return rv;
-}
-
-typedef void (*AccountProc) (Account *a);
-static void traverse_fn (Account *acct, AccountProc fn)
-{
- fn (acct);
+ return nullptr;
}
static void
-acct_traverse_descendants (Account *acct, AccountProc fn)
+acct_traverse_descendants (Account *acct, std::function<void(Account*)> fn)
{
fn (acct);
if (xaccAccountGetReconcileChildrenStatus (acct))
- gnc_account_foreach_descendant (acct, (AccountCb)traverse_fn, (gpointer)fn);
+ gnc_account_foreach_descendant (acct, fn);
}
/********************************************************************\
commit 2902f1de0f25135b9e6e0d8091ea3142ac4b951e
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Tue Jun 18 08:26:30 2024 +0800
[gnc-plugin-page-account-tree.cpp] use c++ algo
diff --git a/gnucash/gnome/gnc-plugin-page-account-tree.cpp b/gnucash/gnome/gnc-plugin-page-account-tree.cpp
index 2db6f0bc8a..b92631b129 100644
--- a/gnucash/gnome/gnc-plugin-page-account-tree.cpp
+++ b/gnucash/gnome/gnc-plugin-page-account-tree.cpp
@@ -34,6 +34,8 @@
#include <config.h>
+#include <algorithm>
+
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include "gnc-plugin-page-account-tree.h"
@@ -1149,21 +1151,11 @@ static gpointer
delete_account_helper (Account * account, gpointer data)
{
auto helper_res = static_cast<delete_helper_t*>(data);
- auto splits{xaccAccountGetSplits (account)};
+ auto& splits{xaccAccountGetSplits (account)};
+ auto split_ro = [](auto s) -> bool { return xaccTransGetReadOnly (xaccSplitGetParent (s)); };
- if (!splits.empty())
- {
- helper_res->has_splits = TRUE;
- for (auto s : splits)
- {
- Transaction *txn = xaccSplitGetParent (s);
- if (xaccTransGetReadOnly (txn))
- {
- helper_res->has_ro_splits = TRUE;
- break;
- }
- }
- }
+ helper_res->has_splits = !splits.empty();
+ helper_res->has_ro_splits = std::any_of (splits.begin(), splits.end(), split_ro);
return GINT_TO_POINTER (helper_res->has_splits || helper_res->has_ro_splits);
}
commit 6790430ee8ba02b1209a9f33a7ba1ffb847072c2
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Tue Jun 18 08:24:37 2024 +0800
[split-register-control.cpp] use c++ algo
diff --git a/gnucash/register/ledger-core/split-register-control.cpp b/gnucash/register/ledger-core/split-register-control.cpp
index c0a8c6519f..1c38c7d3fe 100644
--- a/gnucash/register/ledger-core/split-register-control.cpp
+++ b/gnucash/register/ledger-core/split-register-control.cpp
@@ -26,6 +26,7 @@
#include <glib.h>
#include <glib/gi18n.h>
+#include "Account.hpp"
#include "Scrub.h"
#include "combocell.h"
#include "gnc-component-manager.h"
@@ -668,23 +669,14 @@ static Split *
gnc_find_split_in_account_by_memo (Account *account, const char *memo,
gboolean unit_price)
{
- if (account == NULL) return NULL;
+ if (account == nullptr) return nullptr;
- Split *rv = nullptr;
- auto splits = xaccAccountGetSplitList (account);
- for (auto slp = g_list_last (splits); !rv && slp; slp = slp->prev)
- {
- auto split = GNC_SPLIT(slp->data);
- Transaction *trans = xaccSplitGetParent (split);
-
- split = gnc_find_split_in_trans_by_memo (trans, memo, unit_price);
-
- if (split)
- rv = split;
- }
+ const auto& splits = xaccAccountGetSplits (account);
+ for (auto it = splits.rbegin(); it != splits.rend(); it++)
+ if (auto split = gnc_find_split_in_trans_by_memo (xaccSplitGetParent (*it), memo, unit_price))
+ return split;
- g_list_free (splits);
- return rv;
+ return nullptr;
}
static Split *
Summary of changes:
gnucash/gnome/gnc-plugin-page-account-tree.cpp | 20 +++------
gnucash/gnome/window-reconcile.cpp | 51 +++++++---------------
gnucash/import-export/import-main-matcher.cpp | 36 +++++++--------
.../ledger-core/split-register-control.cpp | 22 +++-------
libgnucash/engine/Account.cpp | 25 +++--------
5 files changed, 50 insertions(+), 104 deletions(-)
More information about the gnucash-changes
mailing list