From 3e3b714ab8f1a27e4697c3df437d9dfa0c949c3f Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sun, 6 Oct 2024 10:41:50 +0800 Subject: [PATCH] [account.cpp] don't use GValue in kvp setters --- libgnucash/engine/Account.cpp | 71 ++++++++--------------------------- 1 file changed, 15 insertions(+), 56 deletions(-) diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp index 49fe34b47e1..d597ba5c46f 100644 --- a/libgnucash/engine/Account.cpp +++ b/libgnucash/engine/Account.cpp @@ -2490,17 +2490,9 @@ set_kvp_gnc_numeric_path (Account *acc, const std::vector& path, g_return_if_fail(GNC_IS_ACCOUNT(acc)); xaccAccountBeginEdit(acc); - if (value.has_value()) - { - GValue v = G_VALUE_INIT; - g_value_init (&v, GNC_TYPE_NUMERIC); - g_value_set_boxed (&v, &*value); - qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, path); - g_value_unset (&v); - } - else - qof_instance_set_path_kvp (QOF_INSTANCE (acc), nullptr, path); - mark_account (acc); + auto inst{QOF_INSTANCE(acc)}; + delete inst->kvp_data->set_path (path, value ? new KvpValue(*value) : nullptr); + qof_instance_set_dirty (inst); xaccAccountCommitEdit(acc); } @@ -2510,18 +2502,9 @@ set_kvp_string_path (Account *acc, const StrVec& path, const char *value) g_return_if_fail(GNC_IS_ACCOUNT(acc)); xaccAccountBeginEdit(acc); - if (value && *value) - { - GValue v = G_VALUE_INIT; - g_value_init (&v, G_TYPE_STRING); - g_value_set_static_string (&v, value); - qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, path); - g_value_unset (&v); - } - else - qof_instance_set_path_kvp (QOF_INSTANCE (acc), nullptr, path); - - qof_instance_set_dirty (QOF_INSTANCE (acc)); + auto inst{QOF_INSTANCE(acc)}; + delete inst->kvp_data->set_path (path, (value && *value) ? new KvpValue(g_strdup(value)) : nullptr); + qof_instance_set_dirty (inst); xaccAccountCommitEdit(acc); } @@ -2539,18 +2522,11 @@ set_kvp_account_path (Account* acc, const StrVec& path, const Account* kvp_accou g_return_if_fail (GNC_IS_ACCOUNT(acc)); xaccAccountBeginEdit(acc); - if (GNC_IS_ACCOUNT(kvp_account)) - { - GValue v = G_VALUE_INIT; - g_value_init (&v, GNC_TYPE_GUID); - g_value_set_static_boxed (&v, xaccAccountGetGUID (kvp_account)); - qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, path); - g_value_unset (&v); - } - else - qof_instance_set_path_kvp (QOF_INSTANCE (acc), nullptr, path); - - qof_instance_set_dirty (QOF_INSTANCE (acc)); + auto inst{QOF_INSTANCE(acc)}; + delete inst->kvp_data->set_path (path, kvp_account + ? new KvpValue(guid_copy(xaccAccountGetGUID (kvp_account))) + : nullptr); + qof_instance_set_dirty (inst); xaccAccountCommitEdit(acc); } @@ -2574,16 +2550,8 @@ get_kvp_account_path (const Account *acc, const StrVec& path) static void set_kvp_boolean_path (Account *acc, const StrVec& path, gboolean option) { - GValue v = G_VALUE_INIT; g_return_if_fail(GNC_IS_ACCOUNT(acc)); - - g_value_init (&v, G_TYPE_BOOLEAN); - g_value_set_boolean (&v, option); - xaccAccountBeginEdit (acc); - qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, path); - mark_account (acc); - xaccAccountCommitEdit (acc); - g_value_unset (&v); + set_kvp_string_path (acc, path, option ? "true" : nullptr); } static gboolean @@ -4059,18 +4027,9 @@ set_kvp_int64_path (Account *acc, const StrVec& path, std::optional valu g_return_if_fail(GNC_IS_ACCOUNT(acc)); xaccAccountBeginEdit(acc); - if (value) - { - GValue v = G_VALUE_INIT; - g_value_init (&v, G_TYPE_INT64); - g_value_set_int64 (&v, *value); - qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, path); - g_value_unset (&v); - } - else - qof_instance_set_path_kvp (QOF_INSTANCE (acc), nullptr, path); - - mark_account (acc); + auto inst{QOF_INSTANCE(acc)}; + delete inst->kvp_data->set_path (path, value ? new KvpValue(*value) : nullptr); + qof_instance_set_dirty (inst); xaccAccountCommitEdit(acc); }