gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Sun Dec 27 20:48:20 EST 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/f1c1fca0 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/bd7b77b9 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/b1f9e8e0 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/ef8f8bdc (commit)
	from  https://github.com/Gnucash/gnucash/commit/76e6b993 (commit)



commit f1c1fca023235a8563243529dd96a792d5ac057f
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Dec 27 12:46:52 2020 +0800

    [account.cpp][API] deprecate xaccAccountCountSplits

diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp
index 5bcfe1a6c..090e7d837 100644
--- a/libgnucash/engine/Account.cpp
+++ b/libgnucash/engine/Account.cpp
@@ -3905,6 +3905,10 @@ xaccAccountCountSplits (const Account *acc, gboolean include_children)
 {
     gint64 nr, i;
 
+    PWARN ("xaccAccountCountSplits is deprecated and will be removed \
+in GnuCash 5.0. If testing for an empty account, use \
+xaccAccountGetSplitList(account) == NULL instead. To test descendants \
+as well, use gnc_account_and_descendants_empty.");
     g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
 
     nr = g_list_length(xaccAccountGetSplitList(acc));

commit bd7b77b9002327b702f9e7b286b8f3a4dc6e0b41
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Dec 27 11:01:07 2020 +0800

    [dialog-account] don't use xaccAccountCountSplits

diff --git a/gnucash/gnome-utils/dialog-account.c b/gnucash/gnome-utils/dialog-account.c
index cd2da43f4..21e839ea9 100644
--- a/gnucash/gnome-utils/dialog-account.c
+++ b/gnucash/gnome-utils/dialog-account.c
@@ -211,7 +211,7 @@ gnc_account_opening_balance_button_update (AccountWindow *aw, gnc_commodity *com
 {
     Account *account = aw_get_account (aw);
     Account *ob_account = gnc_account_lookup_by_opening_balance (gnc_book_get_root_account (aw->book), commodity);
-    gboolean has_splits = xaccAccountCountSplits (account, FALSE) > 0;
+    gboolean has_splits = (xaccAccountGetSplitList (account) != NULL);
 
     if (xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
     {

commit b1f9e8e0400909b3fa22cad3a9669ecca9d4aa24
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Dec 26 23:49:06 2020 +0800

    [html-table][API] deprecate gnc:html-table-append-column!
    
    This function is inefficient. Each column appended will require
    scanning every row of existing html-table, scanning the row's elements
    and appending the desired data.

diff --git a/gnucash/report/html-table.scm b/gnucash/report/html-table.scm
index 91d535cac..e9206548e 100644
--- a/gnucash/report/html-table.scm
+++ b/gnucash/report/html-table.scm
@@ -415,6 +415,8 @@
 (define (gnc:html-table-append-column! table newcol)
   (define width (apply max (cons 0 (map length (gnc:html-table-data table)))))
   (define (add-fn a b) (list-set-safe! b width a))
+  (issue-deprecation-warning "gnc:html-table-append-column! deprecated. please \
+populate html-table row-wise using gnc:html-table-append-row! instead.")
   (let lp ((newcol newcol)
            (olddata (reverse (gnc:html-table-data table)))
            (res '())

commit ef8f8bdcd79a78ca4cd87e7c05eb546a585b2abd
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Dec 26 23:47:07 2020 +0800

    Reports: don't use gnc:html-table-append-column!
    
    This function is inefficient. Each column appended will require
    scanning every row of existing html-table, scanning the row's elements
    and appending the desired data.
    
    It is much more efficient to build a html-table by append rows instead
    -- html-table rows are stored in reverse, and each appended row is
    built using (cons newrow existing-rows).

diff --git a/gnucash/report/reports/example/hello-world.scm b/gnucash/report/reports/example/hello-world.scm
index 59783c3af..9e73e7771 100644
--- a/gnucash/report/reports/example/hello-world.scm
+++ b/gnucash/report/reports/example/hello-world.scm
@@ -427,8 +427,10 @@ new, totally cool report, consult the mailing list ~a.")
 
       (if (not (null? list-val))
           (let ((table (gnc:make-html-table)))
-            (gnc:html-table-append-column! 
-             table (map symbol->string list-val))
+            (for-each
+             (lambda (cell)
+               (gnc:html-table-append-row! table (list (symbol->string cell))))
+             list-val)
             (gnc:html-table-set-style! table "table"
              'attribute (list "style" "width:200px"))
             (gnc:html-table-set-caption! table 
diff --git a/gnucash/report/reports/standard/cashflow-barchart.scm b/gnucash/report/reports/standard/cashflow-barchart.scm
index 9f0e0bf1b..ad9d12b53 100644
--- a/gnucash/report/reports/standard/cashflow-barchart.scm
+++ b/gnucash/report/reports/standard/cashflow-barchart.scm
@@ -35,6 +35,7 @@
 (use-modules (gnucash app-utils))
 (use-modules (gnucash reports cash-flow-calc))
 (use-modules (gnucash report))
+(use-modules (srfi srfi-26))
 
 (define reportname (N_ "Cash Flow Barchart"))
 
@@ -327,6 +328,17 @@
 
           (if (and non-zeros show-table?)
               (let* ((table (gnc:make-html-table)))
+
+                (define (add-row date in out net)
+                  (gnc:html-table-append-row!
+                   table
+                   (cons date
+                         (map (cut gnc:make-html-table-cell/markup "number-cell" <>)
+                              (append
+                               (if show-in?  (list in)  '())
+                               (if show-out? (list out) '())
+                               (if show-net? (list net) '()))))))
+
                 (gnc:html-table-set-col-headers!
                  table (append (list (G_ "Date"))
                                (if show-in? (list (G_ "Money In")) '())
@@ -335,22 +347,9 @@
 
                 (gnc:html-document-add-object!
                  doc (gnc:make-html-text (gnc:html-markup-h3 (G_ "Overview:"))))
-                (gnc:html-table-append-column! table (append date-string-list (list "Total")))
-
-                (if show-in?
-                    (gnc:html-table-append-column! table (append in-list (list total-in))))
-                (if show-out?
-                    (gnc:html-table-append-column! table (append out-list (list total-out))))
-                (if show-net?
-                    (gnc:html-table-append-column! table (append net-list (list total-net))))
-
-                ;; set numeric columns to align right
-                (for-each
-                 (lambda (col)
-                   (gnc:html-table-set-col-style!
-                    table col "td"
-                    'attribute (list "class" "number-cell")))
-                 '(1 2 3))
+
+                (for-each add-row date-string-list in-list out-list net-list)
+                (add-row (G_ "Total") total-in total-out total-net)
 
                 (gnc:html-document-add-object! doc table))))
 
diff --git a/gnucash/report/reports/standard/net-charts.scm b/gnucash/report/reports/standard/net-charts.scm
index 71d8b38b3..1d765bb54 100644
--- a/gnucash/report/reports/standard/net-charts.scm
+++ b/gnucash/report/reports/standard/net-charts.scm
@@ -229,11 +229,7 @@
     ;; This exchanges the commodity-collector 'c' to one single
     ;; 'report-currency' according to the exchange-fn. Returns a gnc:monetary
     (define (collector->monetary c date)
-      (if (not (number? date))
-          (throw 'wrong))
-      (gnc:sum-collector-commodity
-       c report-currency
-       (lambda (a b) (exchange-fn a b date))))
+      (gnc:sum-collector-commodity c report-currency (cut exchange-fn <> <> date)))
 
     ;; gets an account alist balances
     ;; output: (list acc bal0 bal1 bal2 ...)
@@ -425,21 +421,20 @@
                              (list (G_ "Net Profit"))
                              (list (G_ "Net Worth")))
                          '())))
-                   (gnc:html-table-append-column! table date-string-list)
-                   (when show-sep?
-                     (gnc:html-table-append-column! table minuend-balances)
-                     (gnc:html-table-append-column! table subtrahend-balances))
 
-                   (if show-net?
-                       (gnc:html-table-append-column! table difference-balances))
-
-                   ;; set numeric columns to align right
                    (for-each
-                    (lambda (col)
-                      (gnc:html-table-set-col-style!
-                       table col "td"
-                       'attribute (list "class" "number-cell")))
-                    '(1 2 3))
+                    (lambda (date minuend subtrahend difference)
+                      (gnc:html-table-append-row!
+                       table
+                       (cons date
+                             (map
+                              (cut gnc:make-html-table-cell/markup "number-cell" <>)
+                              (append (if show-sep? (list minuend subtrahend) '())
+                                      (if show-net? (list difference) '()))))))
+                    date-string-list
+                    minuend-balances
+                    subtrahend-balances
+                    difference-balances)
 
                    (gnc:html-document-add-object! document table)))
 



Summary of changes:
 gnucash/gnome-utils/dialog-account.c               |  2 +-
 gnucash/report/html-table.scm                      |  2 ++
 gnucash/report/reports/example/hello-world.scm     |  6 +++--
 .../report/reports/standard/cashflow-barchart.scm  | 31 +++++++++++-----------
 gnucash/report/reports/standard/net-charts.scm     | 31 +++++++++-------------
 libgnucash/engine/Account.cpp                      |  4 +++
 6 files changed, 39 insertions(+), 37 deletions(-)



More information about the gnucash-changes mailing list