Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Inkscape::Preferences::Entry Class Reference

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.
 
SPCSSAttrgetStyle () const
 Interpret the preference as a CSS style.
 
SPCSSAttrgetInheritedStyle () 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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Entry() [1/3]

Inkscape::Preferences::Entry::Entry ( Glib::ustring  path,
std::optional< Glib::ustring >  value 
)
inline

Construct new Entry.

Parameters
pathPreferences path, e.g., "/options/some_group/some_option"
valueRaw 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.

◆ ~Entry()

Inkscape::Preferences::Entry::~Entry ( )
default

◆ Entry() [2/3]

Inkscape::Preferences::Entry::Entry ( )
inline

Definition at line 171 of file preferences.h.

◆ Entry() [3/3]

Inkscape::Preferences::Entry::Entry ( Entry const &  other)
default

Member Function Documentation

◆ _getDoubleAssumeExisting()

double Inkscape::Preferences::Entry::_getDoubleAssumeExisting ( ) const
private

get double value, assert that the value is set

Definition at line 1013 of file preferences.cpp.

◆ getBool()

◆ getColor()

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().

◆ getDouble()

double Inkscape::Preferences::Entry::getDouble ( double  def = 0.0,
Glib::ustring const &  unit = "" 
) const

Interpret the preference as a floating point value.

Parameters
defDefault value if the preference is not set.
unitSpecifies 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().

◆ getDoubleLimited()

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.

Parameters
defDefault value if the preference is not set.
minMinimum value allowed to return.
maxMaximum value allowed to return.
unitSpecifies 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().

◆ getEntryName()

◆ getInheritedStyle()

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.

Returns
Inherited CSS style that has to be unrefed after use. Never NULL.

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().

◆ getInt()

int Inkscape::Preferences::Entry::getInt ( int  def = 0) const

Interpret the preference as an integer.

Parameters
defDefault 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().

◆ getIntLimited()

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.

Parameters
defDefault value if the preference is not set.
minMinimum value allowed to return.
maxMaximum 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().

◆ getPath()

Glib::ustring const & Inkscape::Preferences::Entry::getPath ( ) const
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().

◆ getString()

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().

◆ getStyle()

SPCSSAttr * Inkscape::Preferences::Entry::getStyle ( ) const

Interpret the preference as a CSS style.

Returns
A CSS style that has to be unrefed when no longer necessary. Never NULL.

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().

◆ getUInt()

unsigned int Inkscape::Preferences::Entry::getUInt ( unsigned int  def = 0) const

Interpret the preference as an unsigned integer.

Parameters
defDefault value if the preference is not set.

Definition at line 987 of file preferences.cpp.

Referenced by Inkscape::Preferences::getUInt().

◆ getUnit()

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().

◆ isConvertibleTo()

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().

◆ isSet()

bool Inkscape::Preferences::Entry::isSet ( ) const
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.

Returns
True if the entry exists.

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().

◆ isValidBool()

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().

◆ isValidColor()

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.

◆ isValidDouble()

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().

◆ isValidInt()

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.

◆ isValidString()

bool Inkscape::Preferences::Entry::isValidString ( ) const
inline

Check if the preference value is a valid String.

Returns
True if the preference is set, as all data is stored as strings.

Definition at line 221 of file preferences.h.

References isSet().

Referenced by Inkscape::UI::Tools::PencilTool::addPowerStrokePencil().

◆ isValidUInt()

bool Inkscape::Preferences::Entry::isValidUInt ( ) const

Member Data Documentation

◆ _pref_path

Glib::ustring Inkscape::Preferences::Entry::_pref_path
private

Definition at line 331 of file preferences.h.

Referenced by getPath().

◆ _value

std::optional<Glib::ustring> Inkscape::Preferences::Entry::_value
private

Definition at line 332 of file preferences.h.

Referenced by isSet().

◆ cached_bool

bool Inkscape::Preferences::Entry::cached_bool = false
mutableprivate

Definition at line 340 of file preferences.h.

◆ cached_double

bool Inkscape::Preferences::Entry::cached_double = false
mutableprivate

Definition at line 344 of file preferences.h.

◆ cached_int

bool Inkscape::Preferences::Entry::cached_int = false
mutableprivate

Definition at line 342 of file preferences.h.

◆ cached_point

bool Inkscape::Preferences::Entry::cached_point = false
mutableprivate

Definition at line 341 of file preferences.h.

◆ cached_uint

bool Inkscape::Preferences::Entry::cached_uint = false
mutableprivate

Definition at line 343 of file preferences.h.

◆ cached_unit

bool Inkscape::Preferences::Entry::cached_unit = false
mutableprivate

Definition at line 345 of file preferences.h.

◆ value_bool

bool Inkscape::Preferences::Entry::value_bool = false
mutableprivate

Definition at line 334 of file preferences.h.

◆ value_double

double Inkscape::Preferences::Entry::value_double = 0.
mutableprivate

Definition at line 337 of file preferences.h.

◆ value_int

int Inkscape::Preferences::Entry::value_int = 0
mutableprivate

Definition at line 335 of file preferences.h.

◆ value_uint

unsigned int Inkscape::Preferences::Entry::value_uint = 0
mutableprivate

Definition at line 336 of file preferences.h.

◆ value_unit

Glib::ustring Inkscape::Preferences::Entry::value_unit
mutableprivate

Definition at line 338 of file preferences.h.


The documentation for this class was generated from the following files: