Skip to content

Commit

Permalink
[account.cpp] don't use GValue in kvp setters
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Oct 6, 2024
1 parent 773afbb commit 0d4725d
Showing 1 changed file with 15 additions and 56 deletions.
71 changes: 15 additions & 56 deletions libgnucash/engine/Account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2490,17 +2490,9 @@ set_kvp_gnc_numeric_path (Account *acc, const std::vector<std::string>& 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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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
Expand Down Expand Up @@ -4059,18 +4027,9 @@ set_kvp_int64_path (Account *acc, const StrVec& path, std::optional<gint64> 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);
}

Expand Down

0 comments on commit 0d4725d

Please sign in to comment.