Inkscape
Vector Graphics Editor
|
Data type representing a typeless value of a preference. More...
#include <preferences.h>
Public Member Functions | |
Entry (Glib::ustring path, std::optional< Glib::ustring > value) | |
Construct new Entry. | |
~Entry ()=default | |
Entry () | |
Entry (Entry const &other)=default | |
bool | isSet () const |
Check whether the received entry is set. | |
bool | isValidBool () const |
Check if the preference value can be interpreted as a Boolean. | |
bool | isValidInt () const |
Check if the preference value can be interpreted as an integer without any overflow. | |
bool | isValidUInt () const |
Check if the preference value can be interpreted as an unsigned integer. | |
bool | isValidDouble () const |
Check if the preference value can be interpreted as a floating point value. | |
bool | isConvertibleTo (Glib::ustring const &unit) const |
Check if the preference value can be converted to a particular unit. | |
bool | isValidColor () const |
Check if the preference value can be interpreted as a color. | |
bool | isValidString () const |
Check if the preference value is a valid String. | |
bool | getBool (bool def=false) const |
Interpret the preference as a Boolean value. | |
int | getInt (int def=0) const |
Interpret the preference as an integer. | |
int | getIntLimited (int def=0, int min=INT_MIN, int max=INT_MAX) const |
Interpret the preference as a limited integer. | |
unsigned int | getUInt (unsigned int def=0) const |
Interpret the preference as an unsigned integer. | |
double | getDouble (double def=0.0, Glib::ustring const &unit="") const |
Interpret the preference as a floating point value. | |
double | getDoubleLimited (double def=0.0, double min=DBL_MIN, double max=DBL_MAX, Glib::ustring const &unit="") const |
Interpret the preference as a limited floating point value. | |
Glib::ustring | getString (Glib::ustring const &def="") const |
Interpret the preference as an UTF-8 string. | |
Glib::ustring | getUnit () const |
Interpret the preference as a number followed by a unit (without space), and return this unit string. | |
Colors::Color | getColor (std::string const &def) const |
Interpret the preference as a css color value. | |
SPCSSAttr * | getStyle () const |
Interpret the preference as a CSS style. | |
SPCSSAttr * | getInheritedStyle () const |
Interpret the preference as a CSS style with directory-based inheritance. | |
Glib::ustring const & | getPath () const |
Get the full path of the preference described by this Entry. | |
Glib::ustring | getEntryName () const |
Get the last component of the preference's path. | |
Private Member Functions | |
double | _getDoubleAssumeExisting () const |
get double value, assert that the value is set | |
Private Attributes | |
Glib::ustring | _pref_path |
std::optional< Glib::ustring > | _value |
bool | value_bool = false |
int | value_int = 0 |
unsigned int | value_uint = 0 |
double | value_double = 0. |
Glib::ustring | value_unit |
bool | cached_bool = false |
bool | cached_point = false |
bool | cached_int = false |
bool | cached_uint = false |
bool | cached_double = false |
bool | cached_unit = false |
Data type representing a typeless value of a preference.
This is passed to the observer in the notify() method.
Most methods of Entry
return the preference value at the time the Entry
was created. In a few special cases, values are read "on-demand" from the Preferences
, which is ugly but currently hard to avoid. To avoid surprising behavior, users should drop all previously obtained Entry
variables after any write to Preferences
. The only exception is Preferences
itself, which uses Entry
for caching but takes care to remove all outdated entries.
Definition at line 156 of file preferences.h.
|
inline |
Construct new Entry.
path | Preferences path, e.g., "/options/some_group/some_option" |
value | Raw value string from preferences XML file, or std::nullopt if no preference exists for the given path. |
Definition at line 165 of file preferences.h.
|
default |
|
inline |
Definition at line 171 of file preferences.h.
|
default |
|
private |
get double value, assert that the value is set
Definition at line 1013 of file preferences.cpp.
bool Inkscape::Preferences::Entry::getBool | ( | bool | def = false | ) | const |
Interpret the preference as a Boolean value.
def | Default value if the preference is not set. |
Definition at line 902 of file preferences.cpp.
Referenced by Inkscape::UI::Widget::ColorNotebook::_initUI(), Inkscape::Pref< bool >::changed(), Inkscape::Preferences::getBool(), Inkscape::UI::SimplePrefPusher::notify(), Inkscape::SelCue::BoundingBoxPrefsObserver::notify(), Inkscape::SelTrans::BoundingBoxPrefsObserver::notify(), Inkscape::UI::Tools::ToolBase::set(), Inkscape::UI::Tools::CalligraphicTool::set(), Inkscape::UI::Tools::ConnectorTool::set(), Inkscape::UI::Tools::DynamicBase::set(), Inkscape::UI::Tools::MeshTool::set(), Inkscape::UI::Tools::NodeTool::set(), Inkscape::UI::Tools::SprayTool::set(), Inkscape::UI::Tools::StarTool::set(), and Inkscape::UI::Tools::TweakTool::set().
Colors::Color Inkscape::Preferences::Entry::getColor | ( | std::string const & | def | ) | const |
Interpret the preference as a css color value.
Definition at line 926 of file preferences.cpp.
Referenced by Inkscape::Preferences::getColor().
double Inkscape::Preferences::Entry::getDouble | ( | double | def = 0.0 , |
Glib::ustring const & | unit = "" |
||
) | const |
Interpret the preference as a floating point value.
def | Default value if the preference is not set. |
unit | Specifies the unit of the returned result. Will be ignored when equal to "". If the preference has no unit set, the default unit will be assumed. |
Definition at line 1029 of file preferences.cpp.
References Inkscape::Util::Quantity::convert(), and Inkscape::Preferences::getUnit().
Referenced by Inkscape::Preferences::getDouble(), Inkscape::UI::Tools::DynamicBase::set(), Inkscape::UI::Tools::SpiralTool::set(), Inkscape::UI::Tools::SprayTool::set(), Inkscape::UI::Tools::StarTool::set(), and Inkscape::UI::Tools::TweakTool::set().
double Inkscape::Preferences::Entry::getDoubleLimited | ( | double | def = 0.0 , |
double | min = DBL_MIN , |
||
double | max = DBL_MAX , |
||
Glib::ustring const & | unit = "" |
||
) | const |
Interpret the preference as a limited floating point value.
This method will return the default value if the interpreted value is larger than max
or smaller than min
.
def | Default value if the preference is not set. |
min | Minimum value allowed to return. |
max | Maximum value allowed to return. |
unit | Specifies the unit of the returned result. Will be ignored when equal to "". If the preference has no unit set, the default unit will be assumed. |
Definition at line 1043 of file preferences.cpp.
References Inkscape::Preferences::getDouble().
Referenced by Inkscape::Pref< double >::changed(), Inkscape::Preferences::getDoubleLimited(), Inkscape::UI::Tools::ConnectorTool::set(), Inkscape::UI::Tools::RectTool::set(), and Inkscape::UI::Tools::SprayTool::set().
Glib::ustring Inkscape::Preferences::Entry::getEntryName | ( | ) | const |
Get the last component of the preference's path.
E.g. For "/options/some_group/some_option" it will return "some_option".
Definition at line 1115 of file preferences.cpp.
Referenced by Inkscape::UI::Tools::PenTool::set(), Inkscape::UI::Tools::ToolBase::set(), Inkscape::UI::Tools::InteractiveBooleansTool::set(), Inkscape::UI::Tools::CalligraphicTool::set(), Inkscape::UI::Tools::ConnectorTool::set(), Inkscape::UI::Tools::DynamicBase::set(), Inkscape::UI::Tools::LpeTool::set(), Inkscape::UI::Tools::MeshTool::set(), Inkscape::UI::Tools::NodeTool::set(), Inkscape::UI::Tools::RectTool::set(), Inkscape::UI::Tools::SelectTool::set(), Inkscape::UI::Tools::SpiralTool::set(), Inkscape::UI::Tools::SprayTool::set(), Inkscape::UI::Tools::StarTool::set(), and Inkscape::UI::Tools::TweakTool::set().
SPCSSAttr * Inkscape::Preferences::Entry::getInheritedStyle | ( | ) | const |
Interpret the preference as a CSS style with directory-based inheritance.
This function will look up the preferences with the same entry name in ancestor directories and return the inherited CSS style.
Definition at line 1103 of file preferences.cpp.
References Inkscape::Preferences::_getInheritedStyleForPath(), Inkscape::Preferences::get(), and sp_repr_css_attr_new().
Referenced by Inkscape::Preferences::getInheritedStyle(), and Inkscape::UI::Widget::style_obs_callback().
int Inkscape::Preferences::Entry::getInt | ( | int | def = 0 | ) | const |
Interpret the preference as an integer.
def | Default value if the preference is not set. |
Definition at line 943 of file preferences.cpp.
Referenced by Inkscape::Preferences::getInt(), Inkscape::UI::Tools::DynamicBase::set(), Inkscape::UI::Tools::SprayTool::set(), Inkscape::UI::Tools::StarTool::set(), and Inkscape::UI::Tools::TweakTool::set().
int Inkscape::Preferences::Entry::getIntLimited | ( | int | def = 0 , |
int | min = INT_MIN , |
||
int | max = INT_MAX |
||
) | const |
Interpret the preference as a limited integer.
This method will return the default value if the interpreted value is larger than max
or smaller than min
. Do not use to store Boolean values as integers.
def | Default value if the preference is not set. |
min | Minimum value allowed to return. |
max | Maximum value allowed to return. |
Definition at line 981 of file preferences.cpp.
References Inkscape::Preferences::getInt().
Referenced by Inkscape::Pref< int >::changed(), and Inkscape::Preferences::getIntLimited().
|
inline |
Get the full path of the preference described by this Entry.
Definition at line 320 of file preferences.h.
References _pref_path.
Referenced by Inkscape::UI::Tools::DynamicBase::set().
Glib::ustring Inkscape::Preferences::Entry::getString | ( | Glib::ustring const & | def = "" | ) | const |
Interpret the preference as an UTF-8 string.
If unset, return the default value given by def
.
To store a filename, convert it using Glib::filename_to_utf8().
Definition at line 1049 of file preferences.cpp.
Referenced by Inkscape::Pref< Glib::ustring >::changed(), Inkscape::Preferences::getString(), Inkscape::UI::Tools::PenTool::set(), and Inkscape::UI::Tools::SelectTool::set().
SPCSSAttr * Inkscape::Preferences::Entry::getStyle | ( | ) | const |
Interpret the preference as a CSS style.
Definition at line 1090 of file preferences.cpp.
References sp_repr_css_attr_add_from_string(), and sp_repr_css_attr_new().
Referenced by Inkscape::Preferences::getStyle().
unsigned int Inkscape::Preferences::Entry::getUInt | ( | unsigned int | def = 0 | ) | const |
Interpret the preference as an unsigned integer.
def | Default value if the preference is not set. |
Definition at line 987 of file preferences.cpp.
Referenced by Inkscape::Preferences::getUInt().
Glib::ustring Inkscape::Preferences::Entry::getUnit | ( | ) | const |
Interpret the preference as a number followed by a unit (without space), and return this unit string.
If unset, return "".
Definition at line 1054 of file preferences.cpp.
Referenced by Inkscape::Preferences::getUnit().
bool Inkscape::Preferences::Entry::isConvertibleTo | ( | Glib::ustring const & | unit | ) | const |
Check if the preference value can be converted to a particular unit.
Definition at line 878 of file preferences.cpp.
References Inkscape::Util::Unit::compatibleWith(), Inkscape::Util::UnitTable::get(), Inkscape::Util::UnitTable::getUnit(), and Inkscape::Preferences::getUnit().
|
inline |
Check whether the received entry is set.
This means that the requested preference path exists.
If not, then the get...() functions will return the default value.
Definition at line 182 of file preferences.h.
References _value.
Referenced by Inkscape::LivePathEffect::LPERoughen::doOnApply(), Inkscape::LivePathEffect::Effect::hasDefaultParameters(), Inkscape::Preferences::hasPref(), isValidString(), Inkscape::UI::Tools::MeshTool::new_default(), Inkscape::LivePathEffect::Effect::readallParameters(), and Inkscape::LivePathEffect::Effect::unsetDefaultParam().
bool Inkscape::Preferences::Entry::isValidBool | ( | ) | const |
Check if the preference value can be interpreted as a Boolean.
Definition at line 778 of file preferences.cpp.
Referenced by Inkscape::UI::ThemeContext::add_gtk_css().
bool Inkscape::Preferences::Entry::isValidColor | ( | ) | const |
Check if the preference value can be interpreted as a color.
Definition at line 890 of file preferences.cpp.
bool Inkscape::Preferences::Entry::isValidDouble | ( | ) | const |
Check if the preference value can be interpreted as a floating point value.
This will also return true if the value is a valid unit. (eg: "1.0pt")
Definition at line 850 of file preferences.cpp.
References Inkscape::Util::UnitTable::get(), and Inkscape::Util::UnitTable::hasUnit().
Referenced by Inkscape::UI::Tools::PencilTool::addPowerStrokePencil(), Inkscape::LivePathEffect::LPEJoinType::doOnApply(), and Inkscape::LivePathEffect::LPETaperStroke::doOnApply().
bool Inkscape::Preferences::Entry::isValidInt | ( | ) | const |
Check if the preference value can be interpreted as an integer without any overflow.
It also treats true and false as valid values.
Definition at line 789 of file preferences.cpp.
|
inline |
Check if the preference value is a valid String.
Definition at line 221 of file preferences.h.
References isSet().
Referenced by Inkscape::UI::Tools::PencilTool::addPowerStrokePencil().
bool Inkscape::Preferences::Entry::isValidUInt | ( | ) | const |
Check if the preference value can be interpreted as an unsigned integer.
Definition at line 828 of file preferences.cpp.
Referenced by Inkscape::UI::Dialog::InkscapePreferences::resetIconsColors(), Inkscape::UI::Dialog::InkscapePreferences::symbolicThemeCheck(), and Inkscape::UI::Dialog::InkscapePreferences::toggleSymbolic().
|
private |
Definition at line 331 of file preferences.h.
Referenced by getPath().
|
private |
Definition at line 332 of file preferences.h.
Referenced by isSet().
|
mutableprivate |
Definition at line 340 of file preferences.h.
|
mutableprivate |
Definition at line 344 of file preferences.h.
|
mutableprivate |
Definition at line 342 of file preferences.h.
|
mutableprivate |
Definition at line 341 of file preferences.h.
|
mutableprivate |
Definition at line 343 of file preferences.h.
|
mutableprivate |
Definition at line 345 of file preferences.h.
|
mutableprivate |
Definition at line 334 of file preferences.h.
|
mutableprivate |
Definition at line 337 of file preferences.h.
|
mutableprivate |
Definition at line 335 of file preferences.h.
|
mutableprivate |
Definition at line 336 of file preferences.h.
|
mutableprivate |
Definition at line 338 of file preferences.h.