Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Inkscape::Util::UnitTable Class Reference

#include <units.h>

Public Types

typedef std::unordered_map< Glib::ustring, UnitMetricMetricMap
 
typedef std::unordered_map< Glib::ustring, UnitUnitMap
 
typedef std::unordered_map< unsigned, Unit * > UnitCodeMap
 

Public Member Functions

 UnitTable ()
 Initializes the unit tables and identifies the primary unit types.
 
 UnitTable (std::string const &filename)
 
virtual ~UnitTable ()
 
void addMetric (UnitMetric const &u, bool primary)
 Unit metrics.
 
UnitMetric const * getUnitMetric (Glib::ustring const &name) const
 
void addUnit (Unit const &u, bool primary)
 Add a new unit to the table.
 
Unit const * getUnit (Glib::ustring const &name) const
 Retrieve a given unit based on its string identifier.
 
Unit const * getUnit (char const *name) const
 
Unit const * findUnit (double factor, UnitType type) const
 Try to find a unit based on its conversion factor to the primary.
 
Unit const * getUnit (SVGLength::Unit u) const
 Retrieve a given unit based on its SVGLength unit.
 
Quantity parseQuantity (Glib::ustring const &q) const
 Retrieve a quantity based on its string identifier.
 
bool hasUnit (Glib::ustring const &name) const
 Remove a unit definition from the given unit type table * / DISABLED, unsafe with the current passing around pointers to Unit objects in this table.
 
UnitMap units (UnitType type) const
 Provides an iterable list of items in the given unit table.
 
Glib::ustring primary (UnitType type) const
 Returns the default unit abbr for the given type.
 
double getScale () const
 
void setScale ()
 
bool load (std::string const &filename)
 Load units from an XML file.
 

Static Public Member Functions

static UnitTableget ()
 

Protected Attributes

MetricMap _metric_map
 
UnitCodeMap _unit_map
 
Glib::ustring _primary_unit [UNIT_TYPE_QTY]
 
Glib::ustring _default_metric
 
double _linear_scale
 

Static Protected Attributes

static Unit _empty_unit
 

Private Member Functions

 UnitTable (UnitTable const &t)
 
UnitTable operator= (UnitTable const &t)
 

Detailed Description

Definition at line 145 of file units.h.

Member Typedef Documentation

◆ MetricMap

typedef std::unordered_map<Glib::ustring, UnitMetric> Inkscape::Util::UnitTable::MetricMap

Definition at line 156 of file units.h.

◆ UnitCodeMap

typedef std::unordered_map<unsigned, Unit*> Inkscape::Util::UnitTable::UnitCodeMap

Definition at line 158 of file units.h.

◆ UnitMap

typedef std::unordered_map<Glib::ustring, Unit> Inkscape::Util::UnitTable::UnitMap

Definition at line 157 of file units.h.

Constructor & Destructor Documentation

◆ UnitTable() [1/3]

Inkscape::Util::UnitTable::UnitTable ( )

Initializes the unit tables and identifies the primary unit types.

The primary unit's conversion factor is required to be 1.00

Definition at line 261 of file units.cpp.

References load().

◆ UnitTable() [2/3]

Inkscape::Util::UnitTable::UnitTable ( std::string const &  filename)

Definition at line 266 of file units.cpp.

References load().

◆ ~UnitTable()

Inkscape::Util::UnitTable::~UnitTable ( )
virtual

Definition at line 271 of file units.cpp.

References _unit_map.

◆ UnitTable() [3/3]

Inkscape::Util::UnitTable::UnitTable ( UnitTable const &  t)
private

Member Function Documentation

◆ addMetric()

void Inkscape::Util::UnitTable::addMetric ( UnitMetric const &  u,
bool  primary 
)

Unit metrics.

Definition at line 279 of file units.cpp.

References _default_metric, _metric_map, Inkscape::Util::UnitMetric::name, and primary().

◆ addUnit()

void Inkscape::Util::UnitTable::addUnit ( Unit const &  u,
bool  primary 
)

Add a new unit to the table.

Definition at line 299 of file units.cpp.

References _primary_unit, _unit_map, Inkscape::Util::Unit::abbr, primary(), and Inkscape::Util::Unit::type.

Referenced by Inkscape::UI::Widget::UnitMenu::addUnit().

◆ findUnit()

Unit const * Inkscape::Util::UnitTable::findUnit ( double  factor,
UnitType  type 
) const

Try to find a unit based on its conversion factor to the primary.

Definition at line 333 of file units.cpp.

References _primary_unit, _unit_map, Geom::are_near(), and getUnit().

◆ get()

UnitTable & Inkscape::Util::UnitTable::get ( )
static

Definition at line 441 of file units.cpp.

Referenced by Inkscape::UI::Widget::UnitTracker::_setActive(), Inkscape::UI::Toolbar::PageToolbar::_unit_to_size(), Inkscape::UI::Widget::UnitMenu::addUnit(), Inkscape::Util::Quantity::compatibleWith(), Inkscape::Util::Unit::compatibleWith(), Inkscape::Util::Quantity::convert(), Inkscape::Util::Unit::convert(), Inkscape::Util::Quantity::convert(), Inkscape::Util::Quantity::convert(), Inkscape::Util::Unit::convert(), Inkscape::Util::Quantity::convert(), Inkscape::UI::Widget::Ruler::create_context_menu(), Inkscape::UI::Tools::LpeTool::create_measuring_items(), Inkscape::PaperSize::findPaperSize(), Inkscape::Extension::Internal::TemplateBase::get_template_unit(), Inkscape::UI::Widget::UnitMenu::getConversion(), Inkscape::PaperSize::getPageSizes(), Inkscape::PageManager::getSizeLabel(), Inkscape::UI::Widget::UnitMenu::getUnit(), Inkscape::Util::Unit::getUnitMetric(), Inkscape::Preferences::Entry::isConvertibleTo(), Inkscape::Preferences::Entry::isValidDouble(), Inkscape::UI::Widget::SelectedStyle::make_popup_units(), Inkscape::Extension::Internal::TemplateBase::match_template_size(), Inkscape::UI::Widget::ScalarUnit::on_unit_changed(), Inkscape::UI::Toolbar::PaintbucketToolbar::PaintbucketToolbar(), Inkscape::PaperSize::PaperSize(), Inkscape::LivePathEffect::UnitParam::param_set_value(), Inkscape::Extension::Internal::TemplateBase::resize_to_template(), Inkscape::Util::ExpressionEvaluator::resolveUnit(), Inkscape::UI::Tools::CalligraphicTool::root_handler(), Inkscape::UI::Toolbar::SelectToolbar::SelectToolbar(), Inkscape::UI::Tools::DynamicBase::set(), Inkscape::UI::Widget::UnitTracker::setActiveUnitByAbbr(), Inkscape::UI::Widget::UnitMenu::setUnitType(), sp_parse_document_units(), Inkscape::Util::Quantity::string(), Inkscape::UI::Widget::StrokeStyle::StrokeStyle(), Inkscape::UI::Toolbar::TextToolbar::TextToolbar(), Inkscape::LivePathEffect::UnitParam::UnitParam(), Inkscape::UI::Widget::UnitTracker::UnitTracker(), Inkscape::UI::Tools::LpeTool::update_measuring_items(), Inkscape::UI::Dialog::DocumentProperties::update_widgets(), and Inkscape::Util::Quantity::value().

◆ getScale()

double Inkscape::Util::UnitTable::getScale ( ) const

◆ getUnit() [1/3]

Unit const * Inkscape::Util::UnitTable::getUnit ( char const *  name) const

Definition at line 307 of file units.cpp.

References _empty_unit, and _unit_map.

◆ getUnit() [2/3]

◆ getUnit() [3/3]

Unit const * Inkscape::Util::UnitTable::getUnit ( SVGLength::Unit  u) const

Retrieve a given unit based on its SVGLength unit.

Definition at line 320 of file units.cpp.

References _empty_unit, _unit_map, and SVGLength::LAST_UNIT.

◆ getUnitMetric()

UnitMetric const * Inkscape::Util::UnitTable::getUnitMetric ( Glib::ustring const &  name) const

Definition at line 287 of file units.cpp.

References _default_metric, _metric_map, getUnitMetric(), and name.

Referenced by Inkscape::Util::Unit::getUnitMetric(), and getUnitMetric().

◆ hasUnit()

bool Inkscape::Util::UnitTable::hasUnit ( Glib::ustring const &  name) const

Remove a unit definition from the given unit type table * / DISABLED, unsafe with the current passing around pointers to Unit objects in this table.

Returns true if the given string 'name' is a valid unit in the table

Definition at line 400 of file units.cpp.

References _unit_map.

Referenced by Inkscape::Preferences::Entry::isValidDouble().

◆ load()

bool Inkscape::Util::UnitTable::load ( std::string const &  filename)

Load units from an XML file.

Loads and merges the contents of the given file into the UnitTable, possibly overwriting existing unit definitions.

Parameters
filenamefile to be loaded

Definition at line 423 of file units.cpp.

Referenced by UnitTable(), and UnitTable().

◆ operator=()

UnitTable Inkscape::Util::UnitTable::operator= ( UnitTable const &  t)
private

◆ parseQuantity()

Quantity Inkscape::Util::UnitTable::parseQuantity ( Glib::ustring const &  q) const

Retrieve a quantity based on its string identifier.

Definition at line 355 of file units.cpp.

◆ primary()

Glib::ustring Inkscape::Util::UnitTable::primary ( UnitType  type) const

Returns the default unit abbr for the given type.

Definition at line 418 of file units.cpp.

References _primary_unit.

Referenced by addMetric(), and addUnit().

◆ setScale()

void Inkscape::Util::UnitTable::setScale ( )

◆ units()

UnitTable::UnitMap Inkscape::Util::UnitTable::units ( UnitType  type) const

Provides an iterable list of items in the given unit table.

Definition at line 406 of file units.cpp.

References _unit_map.

Referenced by Inkscape::UI::Widget::Ruler::create_context_menu(), and Inkscape::UI::Widget::UnitTracker::UnitTracker().

Member Data Documentation

◆ _default_metric

Glib::ustring Inkscape::Util::UnitTable::_default_metric
protected

Definition at line 215 of file units.h.

Referenced by addMetric(), and getUnitMetric().

◆ _empty_unit

Unit Inkscape::Util::UnitTable::_empty_unit
staticprotected

Definition at line 218 of file units.h.

Referenced by getUnit(), and getUnit().

◆ _linear_scale

double Inkscape::Util::UnitTable::_linear_scale
protected

Definition at line 217 of file units.h.

◆ _metric_map

MetricMap Inkscape::Util::UnitTable::_metric_map
protected

Definition at line 212 of file units.h.

Referenced by addMetric(), and getUnitMetric().

◆ _primary_unit

Glib::ustring Inkscape::Util::UnitTable::_primary_unit[UNIT_TYPE_QTY]
protected

Definition at line 214 of file units.h.

Referenced by addUnit(), findUnit(), and primary().

◆ _unit_map

UnitCodeMap Inkscape::Util::UnitTable::_unit_map
protected

Definition at line 213 of file units.h.

Referenced by addUnit(), findUnit(), getUnit(), getUnit(), hasUnit(), units(), and ~UnitTable().


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