diff options
| author | Matthew Petroff <matthew@mpetroff.net> | 2013-07-20 18:45:18 +0000 |
|---|---|---|
| committer | Matthew Petroff <matthew@mpetroff.net> | 2013-07-20 18:45:18 +0000 |
| commit | 86abdc99654356a2047571e907b933505dbfab76 (patch) | |
| tree | 9e605d6dbe5fcb03291eff6558478f1cb30c2493 /src/util/units.cpp | |
| parent | Removed last traces of "SPUnit" and removed "helper/unit*". (diff) | |
| download | inkscape-86abdc99654356a2047571e907b933505dbfab76.tar.gz inkscape-86abdc99654356a2047571e907b933505dbfab76.zip | |
Add string output functions for units.
(bzr r12380.1.46)
Diffstat (limited to 'src/util/units.cpp')
| -rw-r--r-- | src/util/units.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/util/units.cpp b/src/util/units.cpp index dcb3ae4b1..01424520b 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -15,6 +15,7 @@ #include <cmath> #include <cerrno> +#include <iomanip> #include <glib.h> #include <glibmm/regex.h> @@ -501,6 +502,18 @@ double Quantity::value(const Glib::ustring u) const return value(unit_table.getUnit(u)); } +/** Return a printable string of the value in the specified unit. */ +Glib::ustring Quantity::string(const Unit &u) const { + return Glib::ustring::format(std::fixed, std::setprecision(2), value(u)) + " " + unit->abbr; +} +Glib::ustring Quantity::string(const Glib::ustring u) const { + static UnitTable unit_table; + return string(unit_table.getUnit(u)); +} +Glib::ustring Quantity::string() const { + return string(*unit); +} + /** Convert distances. */ double Quantity::convert(const double from_dist, const Unit &from, const Unit &to) { |
