gnucash stable: [Transaction.cpp] use qof_instance kvp API for GDate
Christopher Lam
clam at code.gnucash.org
Thu Jul 3 22:40:33 EDT 2025
Updated via https://github.com/Gnucash/gnucash/commit/f3f917df (commit)
from https://github.com/Gnucash/gnucash/commit/fac02813 (commit)
commit f3f917df38799f081a4a522e3b83c8ba1a73af32
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Tue Jun 24 16:32:21 2025 +0800
[Transaction.cpp] use qof_instance kvp API for GDate
diff --git a/libgnucash/engine/Transaction.cpp b/libgnucash/engine/Transaction.cpp
index 26d3aca870..51c7ee7ae8 100644
--- a/libgnucash/engine/Transaction.cpp
+++ b/libgnucash/engine/Transaction.cpp
@@ -1945,16 +1945,13 @@ xaccTransSetDatePostedSecsNormalized (Transaction *trans, time64 time)
void
xaccTransSetDatePostedGDate (Transaction *trans, GDate date)
{
- GValue v = G_VALUE_INIT;
if (!trans) return;
/* We additionally save this date into a kvp frame to ensure in
* the future a date which was set as *date* (without time) can
* clearly be distinguished from the time64. */
- g_value_init (&v, G_TYPE_DATE);
- g_value_set_static_boxed (&v, &date);
- qof_instance_set_kvp (QOF_INSTANCE(trans), &v, 1, TRANS_DATE_POSTED);
- g_value_unset (&v);
+ qof_instance_set_path_kvp<GDate> (QOF_INSTANCE(trans), date, {TRANS_DATE_POSTED});
+ qof_instance_set_dirty (QOF_INSTANCE(trans));
/* mark dirty and commit handled by SetDateInternal */
xaccTransSetDateInternal(trans, &trans->date_posted,
gdate_to_time64(date));
@@ -2301,11 +2298,8 @@ xaccTransGetDatePostedGDate (const Transaction *trans)
/* Can we look up this value in the kvp slot? If yes, use it
* from there because it doesn't suffer from time zone
* shifts. */
- GValue v = G_VALUE_INIT;
- qof_instance_get_kvp (QOF_INSTANCE (trans), &v, 1, TRANS_DATE_POSTED);
- if (G_VALUE_HOLDS_BOXED (&v))
- result = *(GDate*)g_value_get_boxed (&v);
- g_value_unset (&v);
+ if (auto res = qof_instance_get_path_kvp<GDate> (QOF_INSTANCE(trans), {TRANS_DATE_POSTED}))
+ result = *res;
if (! g_date_valid (&result) || gdate_to_time64 (result) == INT64_MAX)
{
/* Well, this txn doesn't have a valid GDate saved in a slot.
diff --git a/libgnucash/engine/qofinstance.cpp b/libgnucash/engine/qofinstance.cpp
index b78724f185..1f41dbd8f4 100644
--- a/libgnucash/engine/qofinstance.cpp
+++ b/libgnucash/engine/qofinstance.cpp
@@ -1081,12 +1081,14 @@ qof_instance_set_path_kvp (QofInstance* inst, std::optional<T> value, const Path
}
template std::optional<Time64> qof_instance_get_path_kvp <Time64> (QofInstance*, const Path&);
+template std::optional<GDate> qof_instance_get_path_kvp <GDate> (QofInstance*, const Path&);
template std::optional<const char*> qof_instance_get_path_kvp <const char*> (QofInstance*, const Path&);
template std::optional<gnc_numeric> qof_instance_get_path_kvp <gnc_numeric> (QofInstance*, const Path&);
template std::optional<GncGUID*> qof_instance_get_path_kvp <GncGUID*> (QofInstance*, const Path&);
template std::optional<int64_t> qof_instance_get_path_kvp <int64_t> (QofInstance*, const Path&);
template void qof_instance_set_path_kvp <Time64> (QofInstance*, std::optional<Time64>, const Path& path);
+template void qof_instance_set_path_kvp <GDate> (QofInstance*, std::optional<GDate>, const Path& path);
template void qof_instance_set_path_kvp <const char*> (QofInstance*, std::optional<const char*>, const Path& path);
template void qof_instance_set_path_kvp <gnc_numeric> (QofInstance*, std::optional<gnc_numeric>, const Path& path);
template void qof_instance_set_path_kvp <GncGUID*> (QofInstance*, std::optional<GncGUID*>, const Path& path);
Summary of changes:
libgnucash/engine/Transaction.cpp | 14 ++++----------
libgnucash/engine/qofinstance.cpp | 2 ++
2 files changed, 6 insertions(+), 10 deletions(-)
More information about the gnucash-changes
mailing list