13 #ifndef mitkPreferences_h
14 #define mitkPreferences_h
20 #include <unordered_map>
24 class IPreferencesStorage;
45 using Properties = std::unordered_map<std::string, std::string>;
69 std::string
Get(
const std::string& key,
const std::string& def)
const override;
70 void Put(
const std::string& key,
const std::string& value)
override;
72 int GetInt(
const std::string& key,
int def)
const override;
73 void PutInt(
const std::string& key,
int value)
override;
75 bool GetBool(
const std::string& key,
bool def)
const override;
76 void PutBool(
const std::string& key,
bool value)
override;
78 float GetFloat(
const std::string& key,
float def)
const override;
79 void PutFloat(
const std::string& key,
float value)
override;
81 double GetDouble(
const std::string& key,
double def)
const override;
82 void PutDouble(
const std::string& key,
double value)
override;
84 std::vector<std::byte>
GetByteArray(
const std::string& key,
const std::byte* def,
size_t size)
const override;
85 void PutByteArray(
const std::string& key,
const std::byte* array,
size_t size)
override;
87 void Override(
const std::string& key,
const std::string& value)
override;
92 void OverrideByteArray(
const std::string& key,
const std::byte* array,
size_t size)
override;
98 bool Remove(
const std::string& key,
bool forceRemoval =
false)
override;
99 void Clear(
bool includeOverrides =
false)
override;
100 std::vector<std::string>
Keys(
bool includeOverrides =
false)
const override;
108 std::string
Name()
const override;
113 const std::vector<std::unique_ptr<Preferences>>&
GetChildren()
const;
117 void SetProperty(
Properties& target,
const std::string& key,
const T& value,
const std::function<std::string(
const T&)>& toString)
119 const auto oldValue = target[key];
120 const auto newValue = toString(value);
121 target[key] = newValue;
123 if (oldValue != newValue)
130 std::optional<std::string> FindValue(
const std::string& key)
const;
134 std::vector<std::unique_ptr<Preferences>> m_Children;
139 IPreferencesStorage* m_Storage;
The backend for persistent preferences.
Event object sent on IPreferences::OnPropertyChanged events.
Interface to application preferences.
Message1< const IPreferences * > OnChanged
Notify on node changes.
Message1< const ChangeEvent & > OnPropertyChanged
Notify on property changes.
Implementation of the IPreferences interface.
std::vector< std::string > ChildrenNames() const override
Get the names of all direct child preference nodes.
void Override(const std::string &key, const std::string &value) override
Set a session-only override for a string property.
const std::vector< std::unique_ptr< Preferences > > & GetChildren() const
IPreferences * Root() override
Get the root preferences node.
double GetDouble(const std::string &key, double def) const override
Get a property value as double.
void PutDouble(const std::string &key, double value) override
Set a double property value.
Preferences(Preferences &&)=default
Preferences & operator=(Preferences &&)=default
void PutInt(const std::string &key, int value) override
Set an int property value.
const IPreferences * Parent() const override
void Flush() override
Write all (!) preferences to disk.
void OverrideFloat(const std::string &key, float value) override
Set a session-only override for a float property.
void PutBool(const std::string &key, bool value) override
Set a bool property value.
Preferences(const Properties &properties, const std::string &name, Preferences *parent, IPreferencesStorage *storage)
Construct a preferences node.
bool GetBool(const std::string &key, bool def) const override
Get a property value as bool.
void OverrideDouble(const std::string &key, double value) override
Set a session-only override for a double property.
std::string AbsolutePath() const override
Get the absolute path (relative to the root node) of this preferences node.
Preferences(const Preferences &)=delete
int GetInt(const std::string &key, int def) const override
Get a property value as int.
Preferences & operator=(const Preferences &)=delete
void OverrideBool(const std::string &key, bool value) override
Set a session-only override for a bool property.
std::vector< std::string > Keys(bool includeOverrides=false) const override
Get the names of all properties of this preferences node.
void OverrideInt(const std::string &key, int value) override
Set a session-only override for an int property.
bool IsOverridden(const std::string &key) const override
Check whether a property has a session-only override.
const Properties & GetProperties() const
std::vector< std::byte > GetByteArray(const std::string &key, const std::byte *def, size_t size) const override
Get a property value as typeless binary representation.
std::unordered_map< std::string, std::string > Properties
Property map type: string keys to string values.
const IPreferences * Root() const override
float GetFloat(const std::string &key, float def) const override
Get a property value as float.
void Put(const std::string &key, const std::string &value) override
Set a property value.
std::string Name() const override
Get the name of this preferences node.
bool Remove(const std::string &key, bool forceRemoval=false) override
Remove a property from this preferences node.
void RemoveNode() override
Remove this preferences node from its parent node.
void OverrideByteArray(const std::string &key, const std::byte *array, size_t size) override
Set a session-only override for a byte array property.
void RemoveOverride(const std::string &key) override
Remove a session-only override for a property.
void Clear(bool includeOverrides=false) override
Remove all properties from this preferences node.
void PutFloat(const std::string &key, float value) override
Set a float property value.
void ClearOverrides() override
Remove all session-only overrides from this preferences node.
IPreferences * Node(const std::string &path) override
Get (and possibly create) the preferences node specified by the given path.
void PutByteArray(const std::string &key, const std::byte *array, size_t size) override
Put binary data into a property value.
IPreferences * Parent() override
Get the parent preferences node or nullptr in case of the root node.
std::string Get(const std::string &key, const std::string &def) const override
Get a property value as string.
Find image slices visible on a given plane.