Skip to content

Commit

Permalink
Change plot-size-option to use a pair
Browse files Browse the repository at this point in the history
This change allows the use of pair to specify plot sizes. They can be a
fixed pixel amount or a percentage.
  • Loading branch information
Bob-IT authored and gjanssens committed Dec 6, 2016
1 parent 4e2b204 commit 1f8c413
Show file tree
Hide file tree
Showing 5 changed files with 309 additions and 126 deletions.
3 changes: 3 additions & 0 deletions src/app-utils/app-utils.scm
Expand Up @@ -111,6 +111,9 @@

(export gnc:make-number-range-option)
(export gnc:make-number-plot-size-option)
(export gnc:plot-size-option-value-type)
(export gnc:plot-size-option-value)

(export gnc:make-internal-option)
(export gnc:make-query-option)
(export gnc:make-color-option)
Expand Down
43 changes: 43 additions & 0 deletions src/app-utils/option-util.c
Expand Up @@ -108,6 +108,8 @@ struct _Getters
SCM date_option_value_type;
SCM date_option_value_absolute;
SCM date_option_value_relative;
SCM plot_size_option_value_type;
SCM plot_size_option_value;
SCM currency_accounting_option_currency_doc_string;
SCM currency_accounting_option_default_currency;
SCM currency_accounting_option_policy_doc_string;
Expand Down Expand Up @@ -596,6 +598,8 @@ initialize_getters(void)
scm_c_eval_string("gnc:date-option-absolute-time");
getters.date_option_value_relative =
scm_c_eval_string("gnc:date-option-relative-time");
getters.plot_size_option_value_type = scm_c_eval_string ("gnc:plot-size-option-value-type");
getters.plot_size_option_value = scm_c_eval_string("gnc:plot-size-option-value");
getters.currency_accounting_option_currency_doc_string =
scm_c_eval_string("gnc:currency-accounting-option-get-curr-doc-string");
getters.currency_accounting_option_default_currency =
Expand Down Expand Up @@ -2667,6 +2671,45 @@ gnc_date_option_value_get_relative (SCM option_value)
return scm_call_1 (getters.date_option_value_relative, option_value);
}

/*******************************************************************\
* gnc_plot_size_option_value_get_type *
* get the type of a plot size option value *
* *
* Args: option_value - option value to get type of *
* Return: newly allocated type string or NULL *
\*******************************************************************/
char *
gnc_plot_size_option_value_get_type (SCM option_value)
{
SCM value;

initialize_getters();

return gnc_scm_call_1_symbol_to_string (getters.plot_size_option_value_type, option_value);
}

/*******************************************************************\
* gnc_plot_size_option_value_get_value *
* get the plot size option value *
* *
* Args: option_value - option value to get the plot size of *
* Return: double value *
\*******************************************************************/
gdouble
gnc_plot_size_option_value_get_value (SCM option_value)
{
SCM value;

initialize_getters();

value = scm_call_1 (getters.plot_size_option_value, option_value);

if (scm_is_number(value))
return scm_to_double (value);
else
return 1.0;
}

/********************************************************************\
* gnc_currency_accounting_option_currency_documentation *
* returns the malloc'ed documentation string for currency *
Expand Down
3 changes: 3 additions & 0 deletions src/app-utils/option-util.h
Expand Up @@ -251,6 +251,9 @@ char * gnc_date_option_value_get_type (SCM option_value);
Timespec gnc_date_option_value_get_absolute (SCM option_value);
SCM gnc_date_option_value_get_relative (SCM option_value);

char * gnc_plot_size_option_value_get_type (SCM option_value);
gdouble gnc_plot_size_option_value_get_value (SCM option_value);

char * gnc_currency_accounting_option_currency_documentation(GNCOption *option);
SCM gnc_currency_accounting_option_get_default_currency(GNCOption *option);
char * gnc_currency_accounting_option_policy_documentation(GNCOption *option);
Expand Down
70 changes: 45 additions & 25 deletions src/app-utils/options.scm
Expand Up @@ -1143,9 +1143,9 @@
(list lower-bound upper-bound num-decimals step-size)
#f #f #f)))


;; plot size options use the option-data as a list whose
;; number plot size options use the option-data as a list whose
;; elements are: (lower-bound upper-bound num-decimals step-size)
;; which is used for the valid pixel range
(define (gnc:make-number-plot-size-option
section
name
Expand All @@ -1157,33 +1157,53 @@
num-decimals
step-size)
(let* ((value default-value)
(value->string (lambda () (number->string value))))
(value->string (lambda ()
(string-append "'" (gnc:value->string value)))))
(gnc:make-option
section name sort-tag 'number-range documentation-string
(lambda () value)
section name sort-tag 'plot-size documentation-string
(lambda () value) ;;getter
(lambda (x)
(cond ((and (pair? x) ;; new pair value
(eq? 'pixels (car x)))
(set! value (cdr x)))
(else (set! value default-value)))
(if (number? x) ;; this is for old style plot size
(set! value (cons 'pixels x))
(set! value x))) ;;setter

(if (number? x) ;; old single value
(set! value x)))
(lambda () default-value)
(gnc:restore-form-generator value->string)
(lambda (f p) (kvp-frame-set-slot-path-gslist f value p))
(lambda (f p)
(let ((v (kvp-frame-get-slot-path-gslist f p)))
(if (and v (number? v))
(set! value v))))
(lambda () default-value) ;;default-getter
(gnc:restore-form-generator value->string) ;;restore-form
(lambda (b p)
(qof-book-set-option b (symbol->string (car value))
(append p '("type")))
(qof-book-set-option b (if (symbol? (cdr value))
(symbol->string (cdr value))
(cdr value))
(append p '("value")))) ;;scm->kvp
(lambda (b p)
(let ((t (qof-book-get-option b (append p '("type"))))
(v (qof-book-get-option b (append p '("value")))))
(if (and t v (string? t))
(set! value (cons (string->symbol t)
(if (string? v) (string->number v) v)))))) ;;kvp->scm
(lambda (x)
(cond ((not (number? x)) (list #f "number-plot-size-option: not a number"))
((and (>= value lower-bound)
(<= value upper-bound))
(list #t x))
(else (list #f "number-plot-size-option: out of range"))))
(list lower-bound upper-bound num-decimals step-size)
#f #f #f)))
(if (eq? 'pixels (car x))
(cond ((not (number? (cdr x))) (list #f "number-plot-size-option-pixels: not a number"))
((and (>= (cdr x) lower-bound)
(<= (cdr x) upper-bound))
(list #t x))
(else (list #f "number-plot-size-option-pixels: out of range")))
(cond ((not (number? (cdr x))) (list #f "number-plot-size-option-percentage: not a number"))
((and (>= (cdr x) 10)
(<= (cdr x) 100))
(list #t x))
(else (list #f "number-plot-size-option-percentage: out of range")))
)
) ;;value-validator
(list lower-bound upper-bound num-decimals step-size) ;;option-data
#f #f #f))) ;;option-data-fns, strings-getter, option-widget-changed-proc

(define (gnc:plot-size-option-value-type option-value)
(car option-value))

(define (gnc:plot-size-option-value option-value)
(cdr option-value))

(define (gnc:make-internal-option
section
Expand Down

0 comments on commit 1f8c413

Please sign in to comment.