API Documentation
Loading...
Searching...
No Matches
ApplicationOptions.h
Go to the documentation of this file.
1#pragma once
2#include "DLLInfo.h"
3#include <NDEVR/String.h>
4#include <NDEVR/GenericOption.h>
5#include <NDEVR/INIFactory.h>
6#include <NDEVR/Dictionary.h>
7namespace NDEVR
8{
9 class INIFactory;
10 class INIOption;
11 class ResourceListener;
12
13 /**--------------------------------------------------------------------------------------------------
14 Class: ApplicationOptionBase
15
16 \brief The core of the default object to store data of any type that should persist through sessions
17 of the application. Developers should use ApplicationOption.
18
19 Stores data of any type that can easily be saved or retrieved at runtime. Option belongs to a
20 specific group for easy sorting and can be used to automatically generate widgets.
21 *-----------------------------------------------------------------------------------------------**/
23 {
24 public:
26 virtual String toString() const = 0;
27 virtual void fromString(const String&) = 0;
28 virtual bool isDefault() const = 0;
29 virtual void setToDefaultValue() = 0;
30 virtual INIOption* iniOption() = 0;
31 };
32 /**--------------------------------------------------------------------------------------------------
33 Class: ApplicationOptions
34
35 \brief The container for storing N-number of ApplicationOption for the program. Almost all options are
36 typically "user options" and are added to that container by default.
37
38 Stores data of any type that can easily be saved or retrieved at runtime. Option belongs to a
39 specific group for easy sorting and can be used to automatically generate widgets.
40 *-----------------------------------------------------------------------------------------------**/
42 {
43 public:
46 {
47 addOption(TranslatedString(), name, value);
48 }
49 void addOption(const TranslatedString& group_name, const TranslatedString& name, ApplicationOptionBase* value)
50 {
51 lib_assert(!m_options[group_name].hasKey(name), "Duplicate entry");
52 m_options[group_name][name] = value;
53 }
55 {
56 return m_options[group][name];
57 }
59 {
60 return getOption(TranslatedString(), name);
61 }
62 void addToINI(INIFactory& factory);
63 void addToINI(const TranslatedString& group_name, INIFactory& factory);
64 void setToDefaults();
65 void setToDefaults(const TranslatedString& group_name);
66 void logOptions(ProgressInfo* log, bool log_only_non_defaults);
67 static ApplicationOptions& UserOptions();
68 protected:
70 };
71
72 /**--------------------------------------------------------------------------------------------------
73 Class: ApplicationOption
74
75 \brief The default object to store data of any type that should persist through sessions of the
76 application.
77
78 Stores data of any type that can easily be saved or retrieved at runtime. Option belongs to a
79 specific group for easy sorting and can be used to automatically generate widgets.
80 *-----------------------------------------------------------------------------------------------**/
81 template<class t_type>
83 {
84 public:
86 : m_group(group)
87 , m_label(label)
88 , m_value(value)
89 , m_options(options)
90 , m_default_value(value)
91 {
93 }
95 : m_label(label)
96 , m_value(value)
97 , m_options(options)
98 , m_default_value(value)
99 {
101 }
102 t_type get() const
103 {
104 return m_value.get();// m_options.getValue<t_type>(m_group, m_label);
105 }
107 {
108 return m_value;
109 }
110 void set(const t_type& value, bool make_default = false)
111 {
112 if (make_default)
113 m_default_value = value;
114 return m_value.set(value);
115 }
116 void setDefaultValue(const t_type& value)
117 {
118 m_default_value = value;
119 }
120 void addListener(ResourceListener* listener, bool silent_add = false)
121 {
122 m_value.addListener(listener, silent_add);
123 }
124 virtual String toString() const override
125 {
126 return String(m_value.get());
127 }
128 virtual void fromString(const String& value) override
129 {
130 m_value.set(value.getAs<t_type>());
131 }
132 virtual bool isDefault() const override
133 {
134 return m_value.get() == m_default_value;
135 }
136 virtual void setToDefaultValue() override
137 {
139 }
140 virtual INIOption* iniOption() override
141 {
143 }
144 const TranslatedString& label() const
145 {
146 return m_label;
147 }
148 const TranslatedString& group() const
149 {
150 return m_group;
151 }
152 protected:
158 };
159
160 /*template<class t_type>
161 class ApplicationUserSetting
162 {
163 public:
164 ApplicationUserSetting(const TranslatedString& label, const t_type& value)
165 : ApplicationOption(_t("User Options"), label, value)
166 {}
167 };*/
168}
#define NDEVR_BASE_API
Definition DLLInfo.h:78
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
The core of the default object to store data of any type that should persist through sessions of the ...
Definition ApplicationOptions.h:23
virtual bool isDefault() const =0
virtual void setToDefaultValue()=0
virtual INIOption * iniOption()=0
virtual String toString() const =0
virtual void fromString(const String &)=0
virtual ~ApplicationOptionBase()
Definition ApplicationOptions.h:25
The default object to store data of any type that should persist through sessions of the application.
Definition Button.h:57
Resource< t_type > & getResource()
Definition ApplicationOptions.h:106
ApplicationOptions & m_options
Definition ApplicationOptions.h:156
virtual void fromString(const String &value) override
Definition ApplicationOptions.h:128
void set(const t_type &value, bool make_default=false)
Definition ApplicationOptions.h:110
virtual void setToDefaultValue() override
Definition ApplicationOptions.h:136
virtual INIOption * iniOption() override
Definition ApplicationOptions.h:140
const TranslatedString m_group
Definition ApplicationOptions.h:153
ApplicationOption(const TranslatedString &group, const TranslatedString &label, const t_type &value, ApplicationOptions &options=ApplicationOptions::UserOptions())
Definition ApplicationOptions.h:85
virtual String toString() const override
Definition ApplicationOptions.h:124
const TranslatedString m_label
Definition ApplicationOptions.h:154
t_type m_default_value
Definition ApplicationOptions.h:157
ApplicationOption(const TranslatedString &label, const t_type &value, ApplicationOptions &options=ApplicationOptions::UserOptions())
Definition ApplicationOptions.h:94
const TranslatedString & label() const
Definition ApplicationOptions.h:144
void addListener(ResourceListener *listener, bool silent_add=false)
Definition ApplicationOptions.h:120
const TranslatedString & group() const
Definition ApplicationOptions.h:148
t_type get() const
Definition ApplicationOptions.h:102
virtual bool isDefault() const override
Definition ApplicationOptions.h:132
Resource< t_type > m_value
Definition ApplicationOptions.h:155
void setDefaultValue(const t_type &value)
Definition ApplicationOptions.h:116
The container for storing N-number of ApplicationOption for the program. Almost all options are typic...
Definition ApplicationOptions.h:42
const ApplicationOptionBase * getOption(const TranslatedString &group, const TranslatedString &name) const
Definition ApplicationOptions.h:54
const ApplicationOptionBase * getOption(const TranslatedString &name) const
Definition ApplicationOptions.h:58
void addOption(const TranslatedString &group_name, const TranslatedString &name, ApplicationOptionBase *value)
Definition ApplicationOptions.h:49
void addOption(const TranslatedString &name, ApplicationOptionBase *value)
Definition ApplicationOptions.h:45
static ApplicationOptions & UserOptions()
Definition ApplicationOptions.cpp:77
Dictionary< TranslatedString, Dictionary< TranslatedString, ApplicationOptionBase * > > m_options
Definition ApplicationOptions.h:69
Definition Dictionary.h:48
Definition INIReader.h:57
static INIOption * ToOption(t_type &mem_loc)
Definition INIReader.h:225
Definition INIReader.h:45
Definition ProgressInfo.hpp:43
Definition Toggle.h:41
Definition ResourceListener.h:55
Definition String.h:40
t_type getAs() const
Definition String.h:334
Definition TranslatedString.h:9
Definition ACIColor.h:37
QAction * group(nullptr)