r23067 - gnucash/trunk/src/report - Report system legacy code cleanup

Geert Janssens gjanssens at code.gnucash.org
Thu Jun 27 05:08:39 EDT 2013


Author: gjanssens
Date: 2013-06-27 05:08:39 -0400 (Thu, 27 Jun 2013)
New Revision: 23067
Trac: http://svn.gnucash.org/trac/changeset/23067

Modified:
   gnucash/trunk/src/report/report-gnome/dialog-custom-report.c
   gnucash/trunk/src/report/report-gnome/dialog-report-column-view.c
   gnucash/trunk/src/report/report-system/report-system.scm
   gnucash/trunk/src/report/report-system/report.scm
Log:
Report system legacy code cleanup

- Rename two functions that work with guids instead of names (legacy)
- Don't sort the a list of guids. This doesn't add value and slows down the report loading code
- Add/improve some comments
- Reorder record accessors for the report-template record

Modified: gnucash/trunk/src/report/report-gnome/dialog-custom-report.c
===================================================================
--- gnucash/trunk/src/report/report-gnome/dialog-custom-report.c	2013-06-27 09:08:25 UTC (rev 23066)
+++ gnucash/trunk/src/report/report-gnome/dialog-custom-report.c	2013-06-27 09:08:39 UTC (rev 23067)
@@ -97,28 +97,28 @@
 static void
 update_report_list(GtkListStore *store, CustomReportDialog *crd)
 {
-    SCM get_names = scm_c_eval_string("gnc:custom-report-template-names");
+    SCM get_rpt_guids = scm_c_eval_string("gnc:custom-report-template-guids");
     SCM template_menu_name = scm_c_eval_string("gnc:report-template-menu-name/report-guid");
-    SCM names;
+    SCM rpt_guids;
     int i;
     GtkTreeIter iter;
 
     gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), COL_NAME, GTK_SORT_ASCENDING);
 
-    crd->reportlist = scm_call_0(get_names);
-    names = crd->reportlist;
+    crd->reportlist = scm_call_0(get_rpt_guids);
+    rpt_guids = crd->reportlist;
 
     gtk_list_store_clear(store);
 
-    if (scm_is_list(names))
+    if (scm_is_list(rpt_guids))
     {
-        /* for all the names in the list, store them, with a reference,
+        /* for all the report guids in the list, store them, with a reference,
         	 in the gtkliststore */
-        for (i = 0; !scm_is_null(names); i++)
+        for (i = 0; !scm_is_null(rpt_guids); i++)
         {
             gchar *name;
 
-            name = gnc_scm_to_locale_string (scm_call_2(template_menu_name, SCM_CAR(names), SCM_BOOL_F));
+            name = gnc_scm_to_locale_string (scm_call_2(template_menu_name, SCM_CAR(rpt_guids), SCM_BOOL_F));
 
             gtk_list_store_append(store, &iter);
             gtk_list_store_set(store, &iter,
@@ -127,7 +127,7 @@
                                -1);
             g_free (name);
 
-            names = SCM_CDR(names);
+            rpt_guids = SCM_CDR(rpt_guids);
         }
     }
 }

Modified: gnucash/trunk/src/report/report-gnome/dialog-report-column-view.c
===================================================================
--- gnucash/trunk/src/report/report-gnome/dialog-report-column-view.c	2013-06-27 09:08:25 UTC (rev 23066)
+++ gnucash/trunk/src/report/report-gnome/dialog-report-column-view.c	2013-06-27 09:08:39 UTC (rev 23067)
@@ -105,10 +105,10 @@
 static void
 update_display_lists(gnc_column_view_edit * view)
 {
-    SCM   get_names = scm_c_eval_string("gnc:all-report-template-names");
+    SCM   get_rpt_guids = scm_c_eval_string("gnc:all-report-template-guids");
     SCM   template_menu_name = scm_c_eval_string("gnc:report-template-menu-name/report-guid");
     SCM   report_menu_name = scm_c_eval_string("gnc:report-menu-name");
-    SCM   names = scm_call_0(get_names);
+    SCM   rpt_guids = scm_call_0(get_rpt_guids);
     SCM   contents =
         gnc_option_db_lookup_option(view->odb, "__general", "report-list",
                                     SCM_BOOL_F);
@@ -136,19 +136,19 @@
     }
 
     scm_gc_unprotect_object(view->available_list);
-    view->available_list = names;
+    view->available_list = rpt_guids;
     scm_gc_protect_object(view->available_list);
 
     store = GTK_LIST_STORE(gtk_tree_view_get_model(view->available));
     gtk_list_store_clear(store);
 
-    if (scm_is_list(names))
+    if (scm_is_list(rpt_guids))
     {
-        for (i = 0; !scm_is_null(names); names = SCM_CDR(names), i++)
+        for (i = 0; !scm_is_null(rpt_guids); rpt_guids = SCM_CDR(rpt_guids), i++)
         {
-            if (scm_is_equal (SCM_CAR(names), selection))
+            if (scm_is_equal (SCM_CAR(rpt_guids), selection))
                 row = i;
-            name = gnc_scm_to_locale_string (scm_call_2(template_menu_name, SCM_CAR(names),
+            name = gnc_scm_to_locale_string (scm_call_2(template_menu_name, SCM_CAR(rpt_guids),
                                                    SCM_BOOL_F));
 
             gtk_list_store_append(store, &iter);

Modified: gnucash/trunk/src/report/report-system/report-system.scm
===================================================================
--- gnucash/trunk/src/report/report-system/report-system.scm	2013-06-27 09:08:25 UTC (rev 23066)
+++ gnucash/trunk/src/report/report-system/report-system.scm	2013-06-27 09:08:39 UTC (rev 23067)
@@ -161,8 +161,8 @@
 (export gnc:report-name)
 (export gnc:report-stylesheet)
 (export gnc:report-set-stylesheet!)
-(export gnc:all-report-template-names)
-(export gnc:custom-report-template-names)
+(export gnc:all-report-template-guids)
+(export gnc:custom-report-template-guids)
 (export gnc:delete-report)
 (export gnc:find-report-template)
 (export gnc:report-generate-restore-forms)

Modified: gnucash/trunk/src/report/report-system/report.scm
===================================================================
--- gnucash/trunk/src/report/report-system/report.scm	2013-06-27 09:08:25 UTC (rev 23066)
+++ gnucash/trunk/src/report/report-system/report.scm	2013-06-27 09:08:39 UTC (rev 23067)
@@ -24,11 +24,32 @@
 (use-modules (gnucash printf))
 (use-modules (sw_report_system))
 
+;; Terminology in this file:
+;; report-template: a report definition of some form. This can be a report
+;;      included in gnucash by default, or a new report definition added by
+;;      the user in the .gnucash directory or a custom report
+;; custom report: like a report-template, but saved with a different set
+;;      of default options. A better name would probably be "preconfigured
+;;      report" or something similar. These templates are managed by the
+;;      user via the "Custom Reports" menu item
+;; report: an instantiation of a report-template (custom or otherwise). One
+;;      specific instance of a template, loaded and configured by the user
+;;      while the program is running.
+;; saved report: a report that was still open at the time a book is closed.
+;;      GnuCash dumps the current settings and template id for such a report
+;;      in a meta file in .gnucash/books. When the book is reopened, the template
+;;      id and settings are used to restore the report to the state it was
+;;      in before the book was closed.
+;;
+;; This file will define record types for report-templates and reports. From what
+;; I understand the latter is used mostly to handle saved reports as defined above,
+;; while the former manages report-templates (including custom-reports).
+
 ;; This hash should contain all the reports available and will be used
 ;; to generate the reports menu whenever a new window opens and to
 ;; figure out what to do when a report needs to be generated.
 ;;
-;; The key is the string naming the report (the report "type") and the
+;; The key is the report guid and the
 ;; value is the report definition structure.
 (define *gnc:_report-templates_* (make-hash-table 23))
 
@@ -46,8 +67,8 @@
 (define gnc:optname-reportname (N_ "Report name"))
 (define gnc:optname-stylesheet (N_ "Stylesheet"))
 
-;; we want to warn users if they've got an old-style, non-guid saved
-;; report, but only once
+;; We want to warn users if they've got an old-style, non-guid custom
+;; report-template, but only once
 (define gnc:old-style-report-warned #f)
 
 ;; A <report-template> represents one of the available report types.
@@ -72,8 +93,8 @@
     ((record-constructor <report-template>)
      #f                         ;; version
      #f                         ;; name
-     #f                         ;; report-guid for backwards compat of newer reports
-     #f                         ;; parent-type for backwards compat of newer reports
+     #f                         ;; report-guid
+     #f                         ;; parent-type (meaning guid of report-template this template is based on)
      #f                         ;; options-generator
      #f                         ;; options-cleanup-cb
      #f                         ;; options-changed-cb
@@ -158,12 +179,12 @@
   (record-modifier <report-template> 'report-guid))
 (define gnc:report-template-name
   (record-accessor <report-template> 'name))
+(define gnc:report-template-set-name
+  (record-modifier <report-template> 'name))
 (define gnc:report-template-parent-type
   (record-accessor <report-template> 'parent-type))
 (define gnc:report-template-set-parent-type!
   (record-modifier <report-template> 'parent-type))
-(define gnc:report-template-set-name
-  (record-modifier <report-template> 'name))
 (define gnc:report-template-options-generator
   (record-accessor <report-template> 'options-generator))
 (define gnc:report-template-options-cleanup-cb
@@ -448,18 +469,17 @@
    (string->symbol 
     (gnc:html-style-sheet-name stylesheet))))
 
-(define (gnc:all-report-template-names)
-  (sort 
+
+;; Load and save helper functions
+
+(define (gnc:all-report-template-guids)
    (hash-fold 
     (lambda (k v p)
       (cons k p)) 
-    '() *gnc:_report-templates_*)
-   string<?))
+    '() *gnc:_report-templates_*))
 
-;; return a list of the custom report template "names" (really a list
-;; of report-guids).
-(define (gnc:custom-report-template-names)
-  (sort 
+;; return a list of the custom report template guids.
+(define (gnc:custom-report-template-guids)
    (hash-fold
     (lambda (k v p)
        (if (gnc:report-template-parent-type v)
@@ -467,12 +487,14 @@
 	    (gnc:debug "template " v)
 	    (cons k p))
 	  p))
-      '() *gnc:_report-templates_*)
-    string<?))
+      '() *gnc:_report-templates_*))
 
 (define (gnc:find-report-template report-type) 
   (hash-ref *gnc:_report-templates_* report-type))
 
+
+;; Load and save functions
+
 (define (gnc:report-generate-restore-forms report)
   ;; clean up the options if necessary.  this is only needed 
   ;; in special cases.  



More information about the gnucash-changes mailing list