GnuCash  4.12-527-g05ffd3d4eb
gnc-optiondb.hpp
Go to the documentation of this file.
1 /********************************************************************\
2  * gnc-optiondb.hpp -- Collection of GncOption objects *
3  * Copyright (C) 2019 John Ralls <jralls@ceridwen.us> *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License*
16  * along with this program; if not, contact: *
17  * *
18  * Free Software Foundation Voice: +1-617-542-5942 *
19  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20  * Boston, MA 02110-1301, USA gnu@gnu.org *
21  * *
22 \********************************************************************/
33 #ifndef GNC_OPTIONDB_HPP_
34 #define GNC_OPTIONDB_HPP_
35 
36 #include <string>
37 #include <functional>
38 #include <exception>
39 #include <optional>
40 #include <iostream>
41 extern "C"
42 {
43 #include <config.h>
44 #include "Account.h"
45 #include "gnc-budget.h"
46 #include "gnc-commodity.h"
47 #include "gncInvoice.h"
48 #include "gncTaxTable.h"
49 }
50 #include "gnc-option.hpp"
51 #include "gnc-datetime.hpp"
52 
53 
54 class GncOptionDB;
55 using GncOptionDBPtr = std::unique_ptr<GncOptionDB>;
56 using GncOptionAccountList = std::vector<GncGUID>;
57 
58 using GncOptionAccountTypeList = std::vector<GNCAccountType>;
59 using GncMultichoiceOptionEntry = std::tuple<const std::string,
60  const std::string,
61  GncOptionMultichoiceKeyType>;
62 using GncMultichoiceOptionChoices = std::vector<GncMultichoiceOptionEntry>;
63 
79 GncOptionAccountList
80 gnc_account_list_from_types(QofBook *book,
81  const GncOptionAccountTypeList& types);
82 
93 void gnc_register_string_option(GncOptionDB* db, const char* section,
94  const char* name, const char* key,
95  const char* doc_string, std::string value);
96 
100 inline void gnc_register_string_option(const GncOptionDBPtr& db,
101  const char* section, const char* name,
102  const char* key, const char* doc_string,
103  std::string value)
104 {
105  gnc_register_string_option(db.get(), section, name, key,
106  doc_string, value);
107 }
108 
119 void gnc_register_text_option(GncOptionDB* db, const char* section,
120  const char* name, const char* key,
121  const char* doc_string, std::string value);
122 
126 inline void gnc_register_text_option(const GncOptionDBPtr& db,
127  const char* section,
128  const char* name, const char* key,
129  const char* doc_string, std::string value)
130 {
131  gnc_register_text_option(db.get(), section, name, key, doc_string, value);
132 }
133 
144 void gnc_register_font_option(GncOptionDB* db, const char* section,
145  const char* name, const char* key,
146  const char* doc_string, std::string value);
147 
151 inline void gnc_register_font_option(const GncOptionDBPtr& db,
152  const char* section, const char* name,
153  const char* key, const char* doc_string,
154  std::string value)
155 {
156  gnc_register_font_option(db.get(), section, name, key, doc_string, value);
157 }
158 
169 void gnc_register_budget_option(GncOptionDB* db, const char* section,
170  const char* name, const char* key,
171  const char* doc_string, GncBudget* value);
172 
176 inline void gnc_register_budget_option(const GncOptionDBPtr& db,
177  const char* section, const char* name,
178  const char* key, const char* doc_string,
179  GncBudget* value)
180 {
181  gnc_register_budget_option(db.get(), section, name, key, doc_string, value);
182 }
183 
195  const char* section, const char* name,
196  const char* key, const char* doc_string,
197  gnc_commodity* value);
198 
202 inline void gnc_register_commodity_option(const GncOptionDBPtr& db,
203  const char* section,
204  const char* name, const char* key,
205  const char* doc_string,
206  gnc_commodity* value)
207 {
208  gnc_register_commodity_option(db.get(), section, name, key,
209  doc_string, value);
210 }
217  const char* section, const char* name,
218  const char* key, const char* doc_string,
219  const char* value);
220 
224 inline void gnc_register_commodity_option(const GncOptionDBPtr& db,
225  const char* section,
226  const char* name, const char* key,
227  const char* doc_string,
228  const char* value)
229 {
230  gnc_register_commodity_option(db.get(), section, name, key,
231  doc_string, value);
232 }
233 
245  const char* section, const char* name,
246  const char* key, const char* doc_string,
247  bool value);
248 
252 inline void gnc_register_simple_boolean_option(const GncOptionDBPtr& db,
253  const char* section,
254  const char* name,
255  const char* key,
256  const char* doc_string,
257  bool value)
258 {
259  gnc_register_simple_boolean_option(db.get(), section, name, key,
260  doc_string, value);
261 }
262 
273 void gnc_register_pixmap_option(GncOptionDB* db, const char* section,
274  const char* name, const char* key,
275  const char* doc_string, std::string value);
276 
280 inline void gnc_register_pixmap_option(GncOptionDBPtr& db, const char* section,
281  const char* name, const char* key,
282  const char* doc_string,
283  std::string value)
284 {
285  gnc_register_pixmap_option(db.get(), section, name, key, doc_string, value);
286 }
287 
300  const char* section,
301  const char* name, const char* key,
302  const char* doc_string,
303  const GncOptionAccountList& value,
304  GncOptionAccountTypeList&& allowed);
305 
309 inline void gnc_register_account_list_limited_option(GncOptionDBPtr& db,
310  const char* section,
311  const char* name, const char* key,
312  const char* doc_string,
313  const GncOptionAccountList& value,
314  GncOptionAccountTypeList&& allowed)
315 {
316  gnc_register_account_list_limited_option(db.get(), section, name, key,
317  doc_string, value,
318  std::move(allowed));
319 }
320 
332  const char* section,
333  const char* name, const char* key,
334  const char* doc_string,
335  const GncOptionAccountList& value);
336 
340 inline void gnc_register_account_list_option(GncOptionDBPtr& db,
341  const char* section,
342  const char* name, const char* key,
343  const char* doc_string,
344  const GncOptionAccountList& value)
345 {
346  gnc_register_account_list_option(db.get(), section, name, key,
347  doc_string, value);
348 }
349 
362  const char* section,
363  const char* name, const char* key,
364  const char* doc_string,
365  const Account* value,
366  GncOptionAccountTypeList&& allowed);
367 
371 inline void gnc_register_account_sel_limited_option(GncOptionDBPtr& db,
372  const char* section,
373  const char* name, const char* key,
374  const char* doc_string,
375  const Account* value,
376  GncOptionAccountTypeList&& allowed)
377 {
378  gnc_register_account_sel_limited_option(db.get(), section, name, key,
379  doc_string, value,
380  std::move(allowed));
381 }
382 
394  const char* section, const char* name,
395  const char* key, const char* doc_string,
396  const char* default_val,
397  GncMultichoiceOptionChoices&& value);
398 
402 inline void gnc_register_multichoice_option(GncOptionDBPtr& db,
403  const char* section, const char* name,
404  const char* key, const char* doc_string,
405  const char* default_val,
406  GncMultichoiceOptionChoices&& value)
407 {
408  gnc_register_multichoice_option(db.get(), section, name,
409  key, doc_string, default_val,
410  std::move(value));
411 }
412 
424 void gnc_register_list_option(GncOptionDB* db, const char* section,
425  const char* name, const char* key,
426  const char* doc_string, const char* value,
427  GncMultichoiceOptionChoices&& list);
428 
432 inline void gnc_register_list_option(GncOptionDBPtr& db, const char* section,
433  const char* name, const char* key,
434  const char* doc_string, const char* value,
435  GncMultichoiceOptionChoices&& list)
436 {
437  gnc_register_list_option(db.get(), section, name, key, doc_string,
438  value, std::move(list));
439 }
440 
456 template <typename ValueType>
458  const char* section, const char* name,
459  const char* key, const char* doc_string,
460  ValueType value, ValueType min,
461  ValueType max, ValueType step);
462 
466 template <typename ValueType>
467 void gnc_register_number_range_option(GncOptionDBPtr& db,
468  const char* section, const char* name,
469  const char* key, const char* doc_string,
470  ValueType value, ValueType min,
471  ValueType max, ValueType step)
472 {
473  gnc_register_number_range_option<ValueType>(db.get(), section, name,
474  key, doc_string, value,
475  min, max, step);
476 }
477 
489  const char* section, const char* name,
490  const char* key,
491  const char* doc_string,
492  int value);
493 
495  const char* section, const char* name,
496  const char* key,
497  const char* doc_string,
498  float value)
499 {
500  gnc_register_number_plot_size_option(db, section, name, key,
501  doc_string, static_cast<int>(value));
502 }
503 
504 
508 inline void gnc_register_number_plot_size_option(const GncOptionDBPtr& db,
509  const char* section,
510  const char* name,
511  const char* key,
512  const char* doc_string,
513  int value)
514 {
515  gnc_register_number_plot_size_option(db.get(), section, name, key,
516  doc_string, value);
517 }
518 
519 inline void gnc_register_number_plot_size_option(const GncOptionDBPtr& db,
520  const char* section,
521  const char* name,
522  const char* key,
523  const char* doc_string,
524  float value)
525 {
526  gnc_register_number_plot_size_option(db.get(), section, name, key,
527  doc_string, static_cast<int>(value));
528 }
529 
540 void gnc_register_query_option(GncOptionDB* db, const char* section,
541  const char* name, const QofQuery* value);
542 
546 inline void gnc_register_query_option(GncOptionDBPtr& db, const char* section,
547  const char* name,
548  const QofQuery* value)
549 {
550  gnc_register_query_option(db.get(), section, name, value);
551 }
552 
564 void gnc_register_owner_option(GncOptionDB* db, const char* section,
565  const char* name, const char* key,
566  const char* doc_string, const GncOwner* value,
567  GncOwnerType type);
568 
572 inline void gnc_register_owner_option(GncOptionDBPtr& db, const char* section,
573  const char* name, const char* key,
574  const char* doc_string,
575  const GncOwner* value,
576  GncOwnerType type)
577 {
578  gnc_register_owner_option(db.get(), section, name, key, doc_string, value, type);
579 }
580 
591 void gnc_register_color_option(GncOptionDB* db, const char* section,
592  const char* name, const char* key,
593  const char* doc_string, std::string value);
594 
598 inline void gnc_register_color_option(GncOptionDBPtr& db, const char* section,
599  const char* name, const char* key,
600  const char* doc_string,
601  std::string value)
602 {
603  gnc_register_color_option(db.get(), section, name, key, doc_string, value);
604 }
605 
606 void gnc_register_internal_option(GncOptionDBPtr& db,
607  const char* section, const char* name,
608  const std::string& value);
609 
610 void gnc_register_internal_option(GncOptionDBPtr& db,
611  const char* section, const char* name,
612  bool value);
613 
614 void gnc_register_report_placement_option(GncOptionDBPtr& db,
615  const char* section, const char* name);
616 
627 void gnc_register_currency_option(GncOptionDB* db, const char* section,
628  const char* name, const char* key,
629  const char* doc_string, gnc_commodity* value);
630 
634 inline void gnc_register_currency_option(const GncOptionDBPtr& db,
635  const char* section,
636  const char* name, const char* key,
637  const char* doc_string,
638  gnc_commodity* value)
639 {
640  gnc_register_currency_option(db.get(), section, name, key,
641  doc_string, value);
642 }
643 
649  const char* section,
650  const char* name, const char* key,
651  const char* doc_string,
652  const char* value);
653 
654 inline void gnc_register_currency_option(const GncOptionDBPtr& db,
655  const char* section,
656  const char* name, const char* key,
657  const char* doc_string,
658  const char* value)
659 {
660  gnc_register_currency_option(db.get(), section, name, key,
661  doc_string, value);
662 }
663 
674 void gnc_register_invoice_option(GncOptionDB* db, const char* section,
675  const char* name, const char* key,
676  const char* doc_string, GncInvoice* value);
677 
681 inline void gnc_register_invoice_option(const GncOptionDBPtr& db,
682  const char* section,
683  const char* name, const char* key,
684  const char* doc_string,
685  GncInvoice* value)
686 {
687  gnc_register_invoice_option(db.get(), section, name, key,
688  doc_string, value);
689 }
690 
701 void gnc_register_taxtable_option(GncOptionDB* db, const char* section,
702  const char* name, const char* key,
703  const char* doc_string, GncTaxTable* value);
704 
708 inline void gnc_register_taxtable_option(const GncOptionDBPtr& db,
709  const char* section, const char* name,
710  const char* key,
711  const char* doc_string,
712  GncTaxTable* value)
713 {
714  gnc_register_taxtable_option(db.get(), section, name, key,
715  doc_string, value);
716 }
717 
728 void gnc_register_counter_option(GncOptionDB* db, const char* section,
729  const char* name, const char* key,
730  const char* doc_string, double value);
731 
735 inline void gnc_register_counter_option(const GncOptionDBPtr& db,
736  const char* section, const char* name,
737  const char* key, const char* doc_string,
738  double value)
739 {
740  gnc_register_counter_option(db.get(), section, name, key,
741  doc_string, value);
742 }
743 
755  const char* section, const char* name,
756  const char* key, const char* doc_string,
757  std::string value);
758 
762 inline void gnc_register_counter_format_option(GncOptionDBPtr& db,
763  const char* section,
764  const char* name,
765  const char* key,
766  const char* doc_string,
767  std::string value)
768 {
769  gnc_register_counter_format_option(db.get(), section, name, key,
770  doc_string, value);
771 }
772 
784  const char* section, const char* name,
785  const char* key, const char* doc_string,
786  std::string value);
787 
791 inline void gnc_register_dateformat_option(GncOptionDBPtr& db,
792  const char* section,
793  const char* name, const char* key,
794  const char* doc_string,
795  std::string value)
796 {
797  gnc_register_dateformat_option(db.get(), section, name, key,
798  doc_string, value);
799 }
800 
801 enum RelativeDateUI : uint8_t
802 {
803  ABSOLUTE,
804  RELATIVE,
805  BOTH
806 };
807 
819 void gnc_register_date_option(GncOptionDB* db, const char* section,
820  const char* name, const char* key,
821  const char* doc_string,
822  RelativeDatePeriod period =
823  RelativeDatePeriod::TODAY,
824  RelativeDateUI ui = RelativeDateUI::BOTH);
825 
829 inline void gnc_register_date_option(GncOptionDBPtr& db, const char* section,
830  const char* name, const char* key,
831  const char* doc_string,
832  RelativeDatePeriod period =
833  RelativeDatePeriod::TODAY,
834  RelativeDateUI ui = RelativeDateUI::BOTH)
835 {
836  gnc_register_date_option(db.get(), section, name, key, doc_string,
837  period, ui);
838 }
839 
851 void gnc_register_date_option(GncOptionDB* db, const char* section,
852  const char* name, const char* key,
853  const char* doc_string, time64 time,
854  RelativeDateUI ui = RelativeDateUI::BOTH);
855 
859 inline void gnc_register_date_option(GncOptionDBPtr& db, const char* section,
860  const char* name, const char* key,
861  const char* doc_string, time64 time,
862  RelativeDateUI ui = RelativeDateUI::BOTH)
863 {
864  gnc_register_date_option(db.get(), section, name, key, doc_string,
865  time, ui);
866 }
867 
879 void gnc_register_date_option(GncOptionDB* db, const char* section,
880  const char* name, const char* key,
881  const char* doc_string,
882  RelativeDatePeriodVec& period_set,
883  bool both = true);
884 
888 inline void gnc_register_date_option(GncOptionDBPtr& db, const char* section,
889  const char* name, const char* key,
890  const char* doc_string,
891  RelativeDatePeriodVec& period_set,
892  bool both = true)
893 {
894  gnc_register_date_option(db.get(), section, name, key, doc_string,
895  period_set, both);
896 }
897 
909  const char* section,
910  const char* name, const char* key,
911  const char* doc_string, bool both = true);
912 
916 inline void gnc_register_start_date_option(GncOptionDBPtr& db,
917  const char* section,
918  const char* name, const char* key,
919  const char* doc_string, bool both = true)
920 {
921  gnc_register_start_date_option(db.get(), section, name, key, doc_string,
922  both);
923 }
924 
935 void gnc_register_end_date_option(GncOptionDB* db, const char* section,
936  const char* name, const char* key,
937  const char* doc_string, bool both = true);
938 
942 inline void gnc_register_end_date_option(GncOptionDBPtr& db, const char* section,
943  const char* name, const char* key,
944  const char* doc_string, bool both = true)
945 {
946  gnc_register_end_date_option(db.get(), section, name, key, doc_string,
947  both);
948 }
949 
950 
951 
952 #endif //GNC_OPTIONDB_HPP_
Holds all of the options for a book, report, or stylesheet, organized by GncOptionSections.
void gnc_register_simple_boolean_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, bool value)
Create a new simple boolean option and register it in the options database.
void gnc_register_date_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, RelativeDatePeriod period=RelativeDatePeriod::TODAY, RelativeDateUI ui=RelativeDateUI::BOTH)
Create a new date option and register it in the options database.
GnuCash Budgets.
void gnc_register_number_range_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, ValueType value, ValueType min, ValueType max, ValueType step)
Create a new number range option and register it in the options database.
void gnc_register_multichoice_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const char *default_val, GncMultichoiceOptionChoices &&value)
Create a new multichoice option and register it in the options database.
C++ Public interface for individual options.
void gnc_register_query_option(GncOptionDB *db, const char *section, const char *name, const QofQuery *value)
Create a new QofQuery option and register it in the options database.
void gnc_register_number_plot_size_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, int value)
Create a new plot-size option and register it in the options database.
Account handling public routines.
void gnc_register_counter_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, double value)
Create a new counter option and register it in the options database.
void gnc_register_account_sel_limited_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const Account *value, GncOptionAccountTypeList &&allowed)
Create a limited account selection option and register it in the options database.
void gnc_register_start_date_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, bool both=true)
Create a new start-date option and register it in the options database.
void gnc_register_list_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const char *value, GncMultichoiceOptionChoices &&list)
Create a new list option and register it in the options database.
RelativeDatePeriod
Reporting periods relative to the current date.
void gnc_register_dateformat_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new date format option and register it in the options database.
void gnc_register_color_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new color option and register it in the options database.
void gnc_register_string_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new string option and register it in the options database.
void gnc_register_account_list_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const GncOptionAccountList &value)
Create a new account list option and register it in the options database.
void gnc_register_commodity_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, gnc_commodity *value)
Create a new commodity option and register it in the options database.
Tax Table programming interface.
void gnc_register_end_date_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, bool both=true)
Create a new end-date option and register it in the options database.
Business Invoice Interface.
void gnc_register_taxtable_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, GncTaxTable *value)
Create a new taxtable option and register it in the options database.
void gnc_register_font_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new font option and register it in the options database.
void gnc_register_pixmap_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new pixmap option and register it in the options database.
gint64 time64
Many systems, including Microsoft Windows and BSD-derived Unixes like Darwin, are retaining the int-3...
Definition: gnc-date.h:93
void gnc_register_budget_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, GncBudget *value)
Create a new budget option and register it in the options database.
void gnc_register_currency_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, gnc_commodity *value)
Create a new currency option and register it in the options database.
A Query.
Definition: qofquery.cpp:77
void gnc_register_invoice_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, GncInvoice *value)
Create a new invoice option and register it in the options database.
GncOptionAccountList gnc_account_list_from_types(QofBook *book, const GncOptionAccountTypeList &types)
Extract a list of accounts in the book having one of the GNCAccountTypes in types.
void gnc_register_counter_format_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new counter format option and register it in the options database.
void gnc_register_text_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new text option and register it in the options database.
Commodity handling public routines.
modtime is the internal date of the last modtime See src/doc/business.txt for an explanation of the f...
void gnc_register_owner_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const GncOwner *value, GncOwnerType type)
Create a new GncOwner option and register it in the options database.
void gnc_register_account_list_limited_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const GncOptionAccountList &value, GncOptionAccountTypeList &&allowed)
Create a new limited account list option and register it in the options database. ...