summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2013-10-12 22:24:05 +0000
committerJohan B. C. Engelen <j.b.c.engelen@alumnus.utwente.nl>2013-10-12 22:24:05 +0000
commita970dc423d59ea844bdb1af48d5d9419a5e2a287 (patch)
tree8f6a51df0574fe048ae7e791f276e72716aa090c
parentFix crash with experimental lpe tool. (diff)
downloadinkscape-a970dc423d59ea844bdb1af48d5d9419a5e2a287.tar.gz
inkscape-a970dc423d59ea844bdb1af48d5d9419a5e2a287.zip
Units: stop newing Unit objects. pass around pointers to "undeletable" Unit objects in the UnitTable. I think we should move to using indexed units, and pass around the index of the unit in the unittable, or smth like that... ?
(bzr r12679)
-rw-r--r--src/arc-context.cpp4
-rw-r--r--src/display/canvas-axonomgrid.cpp19
-rw-r--r--src/display/canvas-grid.cpp28
-rw-r--r--src/display/canvas-grid.h2
-rw-r--r--src/document.cpp35
-rw-r--r--src/extension/internal/emf-inout.cpp2
-rw-r--r--src/extension/internal/wmf-inout.cpp2
-rw-r--r--src/live_effects/parameter/unit.cpp4
-rw-r--r--src/lpe-tool-context.cpp8
-rw-r--r--src/pen-context.cpp2
-rw-r--r--src/preferences.cpp3
-rw-r--r--src/rect-context.cpp4
-rw-r--r--src/seltrans.cpp8
-rw-r--r--src/sp-guide.cpp4
-rw-r--r--src/sp-namedview.cpp25
-rw-r--r--src/sp-namedview.h2
-rw-r--r--src/sp-text.cpp2
-rw-r--r--src/spiral-context.cpp2
-rw-r--r--src/star-context.cpp2
-rw-r--r--src/text-context.cpp4
-rw-r--r--src/ui/dialog/clonetiler.cpp10
-rw-r--r--src/ui/dialog/document-properties.cpp10
-rw-r--r--src/ui/dialog/export.cpp4
-rw-r--r--src/ui/dialog/guides.cpp2
-rw-r--r--src/ui/tool/node.cpp13
-rw-r--r--src/ui/widget/page-sizer.cpp9
-rw-r--r--src/ui/widget/page-sizer.h4
-rw-r--r--src/ui/widget/preferences-widget.cpp2
-rw-r--r--src/ui/widget/registered-widget.h2
-rw-r--r--src/ui/widget/scalar-unit.cpp10
-rw-r--r--src/ui/widget/scalar-unit.h2
-rw-r--r--src/ui/widget/selected-style.cpp14
-rw-r--r--src/ui/widget/selected-style.h4
-rw-r--r--src/ui/widget/spinbutton.cpp6
-rw-r--r--src/ui/widget/style-swatch.cpp2
-rw-r--r--src/ui/widget/unit-menu.cpp25
-rw-r--r--src/ui/widget/unit-menu.h2
-rw-r--r--src/ui/widget/unit-tracker.cpp27
-rw-r--r--src/ui/widget/unit-tracker.h8
-rw-r--r--src/util/expression-evaluator.cpp10
-rw-r--r--src/util/expression-evaluator.h6
-rw-r--r--src/util/units.cpp64
-rw-r--r--src/util/units.h30
-rw-r--r--src/widgets/desktop-widget.cpp6
-rw-r--r--src/widgets/lpe-toolbar.cpp8
-rw-r--r--src/widgets/measure-toolbar.cpp2
-rw-r--r--src/widgets/node-toolbar.cpp4
-rw-r--r--src/widgets/paintbucket-toolbar.cpp8
-rw-r--r--src/widgets/rect-toolbar.cpp8
-rw-r--r--src/widgets/ruler.cpp18
-rw-r--r--src/widgets/ruler.h4
-rw-r--r--src/widgets/select-toolbar.cpp20
-rw-r--r--src/widgets/stroke-style.cpp30
-rw-r--r--src/widgets/stroke-style.h2
54 files changed, 268 insertions, 270 deletions
diff --git a/src/arc-context.cpp b/src/arc-context.cpp
index dc869ce60..a14562a32 100644
--- a/src/arc-context.cpp
+++ b/src/arc-context.cpp
@@ -418,8 +418,8 @@ void SPArcContext::drag(Geom::Point pt, guint state) {
Inkscape::Util::Quantity rdimx_q = Inkscape::Util::Quantity(rdimx, "px");
Inkscape::Util::Quantity rdimy_q = Inkscape::Util::Quantity(rdimy, "px");
- GString *xs = g_string_new(rdimx_q.string(*desktop->namedview->doc_units).c_str());
- GString *ys = g_string_new(rdimy_q.string(*desktop->namedview->doc_units).c_str());
+ GString *xs = g_string_new(rdimx_q.string(desktop->namedview->doc_units).c_str());
+ GString *ys = g_string_new(rdimy_q.string(desktop->namedview->doc_units).c_str());
if (state & GDK_CONTROL_MASK) {
int ratio_x, ratio_y;
diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp
index 654144122..d66b97bbc 100644
--- a/src/display/canvas-axonomgrid.cpp
+++ b/src/display/canvas-axonomgrid.cpp
@@ -161,15 +161,16 @@ CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_r
: CanvasGrid(nv, in_repr, in_doc, GRID_AXONOMETRIC)
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- gridunit = new Inkscape::Util::Unit(unit_table.getUnit(prefs->getString("/options/grids/axonom/units")));
- if (!gridunit)
- gridunit = new Inkscape::Util::Unit(unit_table.getUnit("px"));
- origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_x", 0.0), *gridunit, "px");
- origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_y", 0.0), *gridunit, "px");
+ gridunit = unit_table.getUnit(prefs->getString("/options/grids/axonom/units"));
+ if (!gridunit) {
+ gridunit = unit_table.getUnit("px");
+ }
+ origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_x", 0.0), gridunit, "px");
+ origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_y", 0.0), gridunit, "px");
color = prefs->getInt("/options/grids/axonom/color", 0x0000ff20);
empcolor = prefs->getInt("/options/grids/axonom/empcolor", 0x0000ff40);
empspacing = prefs->getInt("/options/grids/axonom/empspacing", 5);
- lengthy = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/spacing_y", 1.0), *gridunit, "px");
+ lengthy = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/spacing_y", 1.0), gridunit, "px");
angle_deg[X] = prefs->getDouble("/options/grids/axonom/angle_x", 30.0);
angle_deg[Z] = prefs->getDouble("/options/grids/axonom/angle_z", 30.0);
angle_deg[Y] = 0;
@@ -370,13 +371,13 @@ _wr.setUpdating (false);
gdouble val;
val = origin[Geom::X];
- val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
+ val = Inkscape::Util::Quantity::convert(val, "px", gridunit);
_rsu_ox->setValue (val);
val = origin[Geom::Y];
- val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
+ val = Inkscape::Util::Quantity::convert(val, "px", gridunit);
_rsu_oy->setValue (val);
val = lengthy;
- double gridy = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
+ double gridy = Inkscape::Util::Quantity::convert(val, "px", gridunit);
_rsu_sy->setValue (gridy);
_rsu_ax->setValue(angle_deg[X]);
diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp
index 5701b91a1..192cc4cba 100644
--- a/src/display/canvas-grid.cpp
+++ b/src/display/canvas-grid.cpp
@@ -399,10 +399,10 @@ void CanvasGrid::setOrigin(Geom::Point const &origin_px)
gdouble val;
val = origin_px[Geom::X];
- val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
+ val = Inkscape::Util::Quantity::convert(val, "px", gridunit);
os_x << val << gridunit->abbr;
val = origin_px[Geom::Y];
- val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
+ val = Inkscape::Util::Quantity::convert(val, "px", gridunit);
os_y << val << gridunit->abbr;
repr->setAttribute("originx", os_x.str().c_str());
repr->setAttribute("originy", os_y.str().c_str());
@@ -489,17 +489,17 @@ CanvasXYGrid::CanvasXYGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPD
: CanvasGrid(nv, in_repr, in_doc, GRID_RECTANGULAR)
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- gridunit = new Inkscape::Util::Unit(unit_table.getUnit(prefs->getString("/options/grids/xy/units")));
+ gridunit = unit_table.getUnit(prefs->getString("/options/grids/xy/units"));
if (!gridunit) {
- gridunit = new Inkscape::Util::Unit(unit_table.getUnit("px"));
+ gridunit = unit_table.getUnit("px");
}
- origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_x", 0.0), *gridunit, "px");
- origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_y", 0.0), *gridunit, "px");
+ origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_x", 0.0), gridunit, "px");
+ origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_y", 0.0), gridunit, "px");
color = prefs->getInt("/options/grids/xy/color", 0x0000ff20);
empcolor = prefs->getInt("/options/grids/xy/empcolor", 0x0000ff40);
empspacing = prefs->getInt("/options/grids/xy/empspacing", 5);
- spacing[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_x", 0.0), *gridunit, "px");
- spacing[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_y", 0.0), *gridunit, "px");
+ spacing[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_x", 0.0), gridunit, "px");
+ spacing[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_y", 0.0), gridunit, "px");
render_dotted = prefs->getBool("/options/grids/xy/dotted", false);
snapper = new CanvasXYGridSnapper(this, &namedview->snap_manager, 0);
@@ -605,7 +605,7 @@ CanvasXYGrid::readRepr()
gridunit = q.unit;
spacing[Geom::X] = q.quantity;
validateScalar(oldVal, &spacing[Geom::X]);
- spacing[Geom::X] = Inkscape::Util::Quantity::convert(spacing[Geom::X], *gridunit, "px");
+ spacing[Geom::X] = Inkscape::Util::Quantity::convert(spacing[Geom::X], gridunit, "px");
}
if ( (value = repr->attribute("spacingy")) ) {
double oldVal = spacing[Geom::Y];
@@ -613,7 +613,7 @@ CanvasXYGrid::readRepr()
gridunit = q.unit;
spacing[Geom::Y] = q.quantity;
validateScalar(oldVal, &spacing[Geom::Y]);
- spacing[Geom::Y] = Inkscape::Util::Quantity::convert(spacing[Geom::Y], *gridunit, "px");
+ spacing[Geom::Y] = Inkscape::Util::Quantity::convert(spacing[Geom::Y], gridunit, "px");
}
if ( (value = repr->attribute("color")) ) {
@@ -753,16 +753,16 @@ CanvasXYGrid::newSpecificWidget()
gdouble val;
val = origin[Geom::X];
- val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
+ val = Inkscape::Util::Quantity::convert(val, "px", gridunit);
_rsu_ox->setValue (val);
val = origin[Geom::Y];
- val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
+ val = Inkscape::Util::Quantity::convert(val, "px", gridunit);
_rsu_oy->setValue (val);
val = spacing[Geom::X];
- double gridx = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
+ double gridx = Inkscape::Util::Quantity::convert(val, "px", gridunit);
_rsu_sx->setValue (gridx);
val = spacing[Geom::Y];
- double gridy = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
+ double gridy = Inkscape::Util::Quantity::convert(val, "px", gridunit);
_rsu_sy->setValue (gridy);
_rcp_gcol->setRgba32 (color);
diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h
index 56ed86e94..078670da7 100644
--- a/src/display/canvas-grid.h
+++ b/src/display/canvas-grid.h
@@ -92,7 +92,7 @@ public:
guint32 empcolor; /**< Color for emphasis lines */
gint empspacing; /**< Spacing between emphasis lines */
- Inkscape::Util::Unit const* gridunit;
+ Inkscape::Util::Unit const* gridunit; /**< points to Unit object in UnitTable (so don't delete it) */
Inkscape::XML::Node * repr;
SPDocument *doc;
diff --git a/src/document.cpp b/src/document.cpp
index b94b72bda..4f57cf080 100644
--- a/src/document.cpp
+++ b/src/document.cpp
@@ -556,8 +556,8 @@ SPDocument *SPDocument::doUnref()
Inkscape::Util::Quantity SPDocument::getWidth() const
{
- g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit()));
- g_return_val_if_fail(this->root != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit()));
+ g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, unit_table.getUnit("")));
+ g_return_val_if_fail(this->root != NULL, Inkscape::Util::Quantity(0.0, unit_table.getUnit("")));
gdouble result = root->width.value;
SVGLength::Unit u = root->width.unit;
@@ -577,7 +577,7 @@ void SPDocument::setWidth(const Inkscape::Util::Quantity &width)
root->width.computed = width.value("px");
/* SVG does not support meters as a unit, so we must translate meters to
* cm when writing */
- if (*width.unit == unit_table.getUnit("m")) {
+ if (*width.unit == *unit_table.getUnit("m")) {
root->width.value = width.value("cm");
root->width.unit = SVGLength::CM;
} else {
@@ -593,8 +593,8 @@ void SPDocument::setWidth(const Inkscape::Util::Quantity &width)
Inkscape::Util::Quantity SPDocument::getHeight() const
{
- g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit()));
- g_return_val_if_fail(this->root != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit()));
+ g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, unit_table.getUnit("")));
+ g_return_val_if_fail(this->root != NULL, Inkscape::Util::Quantity(0.0, unit_table.getUnit("")));
gdouble result = root->height.value;
SVGLength::Unit u = root->height.unit;
@@ -614,7 +614,7 @@ void SPDocument::setHeight(const Inkscape::Util::Quantity &height)
root->height.computed = height.value("px");
/* SVG does not support meters as a unit, so we must translate meters to
* cm when writing */
- if (*height.unit == unit_table.getUnit("m")) {
+ if (*height.unit == *unit_table.getUnit("m")) {
root->height.value = height.value("cm");
root->height.unit = SVGLength::CM;
} else {
@@ -660,7 +660,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins)
double const h = rect.height();
double const old_height = getHeight().value("px");
- Inkscape::Util::Unit const px = unit_table.getUnit("px");
+ Inkscape::Util::Unit const *px = unit_table.getUnit("px");
/* in px */
double margin_top = 0.0;
@@ -674,17 +674,16 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins)
if (nv != NULL) {
gchar const * const units_abbr = nv->getAttribute("units");
Inkscape::Util::Unit const *margin_units = NULL;
- if (units_abbr != NULL) {
- Inkscape::Util::Unit mu = unit_table.getUnit(units_abbr);
- margin_units = &mu;
+ if (units_abbr) {
+ margin_units = unit_table.getUnit(units_abbr);
}
- if (margin_units == NULL) {
- margin_units = &px;
+ if (!margin_units) {
+ margin_units = px;
}
- margin_top = nv->getMarginLength("fit-margin-top",margin_units, &px, w, h, false);
- margin_left = nv->getMarginLength("fit-margin-left",margin_units, &px, w, h, true);
- margin_right = nv->getMarginLength("fit-margin-right",margin_units, &px, w, h, true);
- margin_bottom = nv->getMarginLength("fit-margin-bottom",margin_units, &px, w, h, false);
+ margin_top = nv->getMarginLength("fit-margin-top",margin_units, px, w, h, false);
+ margin_left = nv->getMarginLength("fit-margin-left",margin_units, px, w, h, true);
+ margin_right = nv->getMarginLength("fit-margin-right",margin_units, px, w, h, true);
+ margin_bottom = nv->getMarginLength("fit-margin-bottom",margin_units, px, w, h, false);
}
}
@@ -693,8 +692,8 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins)
rect.max() + Geom::Point(margin_right, margin_top));
- setWidth(Inkscape::Util::Quantity(rect_with_margins.width(), "px"));
- setHeight(Inkscape::Util::Quantity(rect_with_margins.height(), "px"));
+ setWidth(Inkscape::Util::Quantity(rect_with_margins.width(), px));
+ setHeight(Inkscape::Util::Quantity(rect_with_margins.height(), px));
Geom::Translate const tr(
Geom::Point(0, old_height - rect_with_margins.height())
diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp
index 90ab763e0..f1876c687 100644
--- a/src/extension/internal/emf-inout.cpp
+++ b/src/extension/internal/emf-inout.cpp
@@ -3504,7 +3504,7 @@ Emf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri )
doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().quantity, doc->getHeight().quantity));
// Scale and translate objects
- double scale = Inkscape::Util::Quantity::convert(1, "px", doc->getWidth().unit->abbr);
+ double scale = Inkscape::Util::Quantity::convert(1, "px", doc->getWidth().unit);
ShapeEditor::blockSetItem(true);
doc->getRoot()->scaleChildItemsRec(Geom::Scale(scale), Geom::Point(0, SP_ACTIVE_DOCUMENT->getHeight().value("px")));
ShapeEditor::blockSetItem(false);
diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp
index aab98dc87..d69d46f20 100644
--- a/src/extension/internal/wmf-inout.cpp
+++ b/src/extension/internal/wmf-inout.cpp
@@ -3192,7 +3192,7 @@ Wmf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri )
doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().quantity, doc->getHeight().quantity));
// Scale and translate objects
- double scale = Inkscape::Util::Quantity::convert(1, "px", doc->getWidth().unit->abbr);
+ double scale = Inkscape::Util::Quantity::convert(1, "px", doc->getWidth().unit);
ShapeEditor::blockSetItem(true);
doc->getRoot()->scaleChildItemsRec(Geom::Scale(scale), Geom::Point(0, SP_ACTIVE_DOCUMENT->getHeight().value("px")));
ShapeEditor::blockSetItem(false);
diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp
index 561766920..0ee553e2c 100644
--- a/src/live_effects/parameter/unit.cpp
+++ b/src/live_effects/parameter/unit.cpp
@@ -24,7 +24,7 @@ UnitParam::UnitParam( const Glib::ustring& label, const Glib::ustring& tip,
Effect* effect, Glib::ustring default_unit)
: Parameter(label, tip, key, wr, effect)
{
- defunit = new Inkscape::Util::Unit(unit_table.getUnit(default_unit));
+ defunit = unit_table.getUnit(default_unit);
unit = defunit;
}
@@ -36,7 +36,7 @@ bool
UnitParam::param_readSVGValue(const gchar * strvalue)
{
if (strvalue) {
- param_set_value(unit_table.getUnit(strvalue));
+ param_set_value(*unit_table.getUnit(strvalue));
return true;
}
return false;
diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp
index 0b71a892c..bf912746e 100644
--- a/src/lpe-tool-context.cpp
+++ b/src/lpe-tool-context.cpp
@@ -415,7 +415,7 @@ lpetool_create_measuring_items(SPLPEToolContext *lc, Inkscape::Selection *select
if (!show)
sp_canvas_item_hide(SP_CANVAS_ITEM(canvas_text));
- Inkscape::Util::Unit unit;
+ Inkscape::Util::Unit const * unit = NULL;
if (prefs->getString("/tools/lpetool/unit").compare("")) {
unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit"));
} else {
@@ -424,7 +424,7 @@ lpetool_create_measuring_items(SPLPEToolContext *lc, Inkscape::Selection *select
lengthval = Geom::length(pwd2);
lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit);
- arc_length = g_strdup_printf("%.2f %s", lengthval, unit.abbr.c_str());
+ arc_length = g_strdup_printf("%.2f %s", lengthval, unit->abbr.c_str());
sp_canvastext_set_text (canvas_text, arc_length);
set_pos_and_anchor(canvas_text, pwd2, 0.5, 10);
// TODO: must we free arc_length?
@@ -454,7 +454,7 @@ lpetool_update_measuring_items(SPLPEToolContext *lc)
SPPath *path = i->first;
SPCurve *curve = path->getCurve();
Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = Geom::paths_to_pw(curve->get_pathvector());
- Inkscape::Util::Unit unit;
+ Inkscape::Util::Unit const * unit = NULL;
if (prefs->getString("/tools/lpetool/unit").compare("")) {
unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit"));
} else {
@@ -462,7 +462,7 @@ lpetool_update_measuring_items(SPLPEToolContext *lc)
}
double lengthval = Geom::length(pwd2);
lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit);
- gchar *arc_length = g_strdup_printf("%.2f %s", lengthval, unit.abbr.c_str());
+ gchar *arc_length = g_strdup_printf("%.2f %s", lengthval, unit->abbr.c_str());
sp_canvastext_set_text (SP_CANVASTEXT(i->second), arc_length);
set_pos_and_anchor(SP_CANVASTEXT(i->second), pwd2, 0.5, 10);
// TODO: must we free arc_length?
diff --git a/src/pen-context.cpp b/src/pen-context.cpp
index d67bc5e57..428ebd6d9 100644
--- a/src/pen-context.cpp
+++ b/src/pen-context.cpp
@@ -1137,7 +1137,7 @@ static void spdc_pen_set_angle_distance_status_message(SPPenContext *const pc, G
SPDesktop *desktop = SP_EVENT_CONTEXT(pc)->desktop;
Geom::Point rel = p - pc->p[pc_point_to_compare];
Inkscape::Util::Quantity q = Inkscape::Util::Quantity(Geom::L2(rel), "px");
- GString *dist = g_string_new(q.string(*desktop->namedview->doc_units).c_str());
+ GString *dist = g_string_new(q.string(desktop->namedview->doc_units).c_str());
double angle = atan2(rel[Geom::Y], rel[Geom::X]) * 180 / M_PI;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
if (prefs->getBool("/options/compassangledisplay/value", 0) != 0) {
diff --git a/src/preferences.cpp b/src/preferences.cpp
index 0dc6f1ec4..0dcebbb90 100644
--- a/src/preferences.cpp
+++ b/src/preferences.cpp
@@ -785,9 +785,8 @@ double Preferences::_extractDouble(Entry const &v, Glib::ustring const &requeste
if (unit.length() == 0) {
// no unit specified, don't do conversion
return val;
- } else {
- return val * (unit_table.getUnit(unit).factor / unit_table.getUnit(requested_unit).factor);
}
+ return val * (unit_table.getUnit(unit)->factor / unit_table.getUnit(requested_unit)->factor); /// \todo rewrite using Quantity class, so the standard code handles unit conversion
}
Glib::ustring Preferences::_extractString(Entry const &v)
diff --git a/src/rect-context.cpp b/src/rect-context.cpp
index f60b3d465..a0e751359 100644
--- a/src/rect-context.cpp
+++ b/src/rect-context.cpp
@@ -426,8 +426,8 @@ void SPRectContext::drag(Geom::Point const pt, guint state) {
Inkscape::Util::Quantity rdimx_q = Inkscape::Util::Quantity(rdimx, "px");
Inkscape::Util::Quantity rdimy_q = Inkscape::Util::Quantity(rdimy, "px");
- GString *xs = g_string_new(rdimx_q.string(*desktop->namedview->doc_units).c_str());
- GString *ys = g_string_new(rdimy_q.string(*desktop->namedview->doc_units).c_str());
+ GString *xs = g_string_new(rdimx_q.string(desktop->namedview->doc_units).c_str());
+ GString *ys = g_string_new(rdimy_q.string(desktop->namedview->doc_units).c_str());
if (state & GDK_CONTROL_MASK) {
int ratio_x, ratio_y;
diff --git a/src/seltrans.cpp b/src/seltrans.cpp
index f614853bc..7a8f5ec17 100644
--- a/src/seltrans.cpp
+++ b/src/seltrans.cpp
@@ -1274,8 +1274,8 @@ gboolean Inkscape::SelTrans::centerRequest(Geom::Point &pt, guint state)
// status text
Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(pt[Geom::X], "px");
Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(pt[Geom::Y], "px");
- GString *xs = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str());
- GString *ys = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str());
+ GString *xs = g_string_new(x_q.string(_desktop->namedview->doc_units).c_str());
+ GString *ys = g_string_new(y_q.string(_desktop->namedview->doc_units).c_str());
_message_context.setF(Inkscape::NORMAL_MESSAGE, _("Move <b>center</b> to %s, %s"), xs->str, ys->str);
g_string_free(xs, FALSE);
g_string_free(ys, FALSE);
@@ -1428,8 +1428,8 @@ void Inkscape::SelTrans::moveTo(Geom::Point const &xy, guint state)
// status text
Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dxy[Geom::X], "px");
Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dxy[Geom::Y], "px");
- GString *xs = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str());
- GString *ys = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str());
+ GString *xs = g_string_new(x_q.string(_desktop->namedview->doc_units).c_str());
+ GString *ys = g_string_new(y_q.string(_desktop->namedview->doc_units).c_str());
_message_context.setF(Inkscape::NORMAL_MESSAGE, _("<b>Move</b> by %s, %s; with <b>Ctrl</b> to restrict to horizontal/vertical; with <b>Shift</b> to disable snapping"), xs->str, ys->str);
g_string_free(xs, TRUE);
g_string_free(ys, TRUE);
diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp
index 83d2d8e78..a0aa9692e 100644
--- a/src/sp-guide.cpp
+++ b/src/sp-guide.cpp
@@ -476,8 +476,8 @@ char *sp_guide_description(SPGuide const *guide, const bool verbose)
Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(guide->point_on_line[X], "px");
Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(guide->point_on_line[Y], "px");
- GString *position_string_x = g_string_new(x_q.string(*namedview->doc_units).c_str());
- GString *position_string_y = g_string_new(y_q.string(*namedview->doc_units).c_str());
+ GString *position_string_x = g_string_new(x_q.string(namedview->doc_units).c_str());
+ GString *position_string_y = g_string_new(y_q.string(namedview->doc_units).c_str());
gchar *shortcuts = g_strdup_printf("; %s", _("<b>Shift+drag</b> to rotate, <b>Ctrl+drag</b> to move origin, <b>Del</b> to delete"));
diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp
index 4464a0be2..ad497ff2f 100644
--- a/src/sp-namedview.cpp
+++ b/src/sp-namedview.cpp
@@ -557,12 +557,11 @@ void SPNamedView::set(unsigned int key, const gchar* value) {
* in that they aren't in general absolute units as currently required by
* doc_units.
*/
- static Inkscape::Util::Unit px = unit_table.getUnit("px");
- Inkscape::Util::Unit const *new_unit = new Inkscape::Util::Unit(px);
+ static Inkscape::Util::Unit const *px = unit_table.getUnit("px");
+ Inkscape::Util::Unit const *new_unit = px;
if (value) {
- Inkscape::Util::Unit u = unit_table.getUnit(value);
- Inkscape::Util::Unit const *const req_unit = new Inkscape::Util::Unit(u);
+ Inkscape::Util::Unit const *const req_unit = unit_table.getUnit(value);
if ( !unit_table.hasUnit(value) ) {
g_warning("Unrecognized unit `%s'", value);
/* fixme: Document errors should be reported in the status bar or
@@ -585,8 +584,7 @@ void SPNamedView::set(unsigned int key, const gchar* value) {
Inkscape::Util::Unit const *new_unit = NULL;
if (value) {
- Inkscape::Util::Unit u = unit_table.getUnit(value);
- Inkscape::Util::Unit const *const req_unit = new Inkscape::Util::Unit(u);
+ Inkscape::Util::Unit const *const req_unit = unit_table.getUnit(value);
if ( !unit_table.hasUnit(value) ) {
g_warning("Unrecognized unit `%s'", value);
/* fixme: Document errors should be reported in the status bar or
@@ -1114,14 +1112,14 @@ double SPNamedView::getMarginLength(gchar const * const key,
bool const use_width)
{
double value;
- Inkscape::Util::Unit percent = unit_table.getUnit("%");
+ static Inkscape::Util::Unit const *percent = unit_table.getUnit("%");
if(!this->storeAsDouble(key,&value)) {
return 0.0;
}
- if (*margin_units == percent) {
+ if (*margin_units == *percent) {
return (use_width)? width * value : height * value;
}
- if (!margin_units->compatibleWith(*return_units)) {
+ if (!margin_units->compatibleWith(return_units)) {
return 0.0;
}
return value;
@@ -1129,14 +1127,11 @@ double SPNamedView::getMarginLength(gchar const * const key,
/**
* Returns namedview's default unit.
+ * If no default unit is set, "pt" is returned
*/
-Inkscape::Util::Unit const SPNamedView::getDefaultUnit() const
+Inkscape::Util::Unit const * SPNamedView::getDefaultUnit() const
{
- if (doc_units) {
- return *doc_units;
- } else {
- return *(new Inkscape::Util::Unit(unit_table.getUnit("pt")));
- }
+ return doc_units ? doc_units : unit_table.getUnit("pt");
}
/**
diff --git a/src/sp-namedview.h b/src/sp-namedview.h
index 30f962d9f..00302e9a1 100644
--- a/src/sp-namedview.h
+++ b/src/sp-namedview.h
@@ -82,7 +82,7 @@ public:
gchar const *getName() const;
guint getViewCount();
GSList const *getViewList() const;
- Inkscape::Util::Unit const getDefaultUnit() const;
+ Inkscape::Util::Unit const * getDefaultUnit() const;
void translateGuides(Geom::Translate const &translation);
void translateGrids(Geom::Translate const &translation);
diff --git a/src/sp-text.cpp b/src/sp-text.cpp
index c431f52da..de5e63fe6 100644
--- a/src/sp-text.cpp
+++ b/src/sp-text.cpp
@@ -348,7 +348,7 @@ gchar* SPText::description() {
}
Inkscape::Util::Quantity q = Inkscape::Util::Quantity(style->font_size.computed, "px");
- GString *xs = g_string_new(q.string(*sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units).c_str());
+ GString *xs = g_string_new(q.string(sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units).c_str());
char const *trunc = "";
Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) this);
diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp
index 24a3ea6de..9d44b5adb 100644
--- a/src/spiral-context.cpp
+++ b/src/spiral-context.cpp
@@ -399,7 +399,7 @@ void SPSpiralContext::drag(Geom::Point const &p, guint state) {
/* status text */
Inkscape::Util::Quantity q = Inkscape::Util::Quantity(rad, "px");
- GString *rads = g_string_new(q.string(*desktop->namedview->doc_units).c_str());
+ GString *rads = g_string_new(q.string(desktop->namedview->doc_units).c_str());
this->message_context->setF(Inkscape::IMMEDIATE_MESSAGE,
_("<b>Spiral</b>: radius %s, angle %5g&#176;; with <b>Ctrl</b> to snap angle"),
rads->str, sp_round((arg + 2.0*M_PI*this->spiral->revo)*180/M_PI, 0.0001));
diff --git a/src/star-context.cpp b/src/star-context.cpp
index 30112cbe9..d801ad0a0 100644
--- a/src/star-context.cpp
+++ b/src/star-context.cpp
@@ -417,7 +417,7 @@ void SPStarContext::drag(Geom::Point p, guint state)
/* status text */
Inkscape::Util::Quantity q = Inkscape::Util::Quantity(r1, "px");
- GString *rads = g_string_new(q.string(*desktop->namedview->doc_units).c_str());
+ GString *rads = g_string_new(q.string(desktop->namedview->doc_units).c_str());
this->message_context->setF(Inkscape::IMMEDIATE_MESSAGE,
( this->isflatsided?
_("<b>Polygon</b>: radius %s, angle %5g&#176;; with <b>Ctrl</b> to snap angle")
diff --git a/src/text-context.cpp b/src/text-context.cpp
index f12ce6aa6..7d9b9848f 100644
--- a/src/text-context.cpp
+++ b/src/text-context.cpp
@@ -601,8 +601,8 @@ bool SPTextContext::root_handler(GdkEvent* event) {
// status text
Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(fabs((p - this->p0)[Geom::X]), "px");
Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(fabs((p - this->p0)[Geom::Y]), "px");
- GString *xs = g_string_new(x_q.string(*desktop->namedview->doc_units).c_str());
- GString *ys = g_string_new(y_q.string(*desktop->namedview->doc_units).c_str());
+ GString *xs = g_string_new(x_q.string(desktop->namedview->doc_units).c_str());
+ GString *ys = g_string_new(y_q.string(desktop->namedview->doc_units).c_str());
this->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Flowed text frame</b>: %s &#215; %s"), xs->str, ys->str);
g_string_free(xs, FALSE);
diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp
index b3675440b..87c399339 100644
--- a/src/ui/dialog/clonetiler.cpp
+++ b/src/ui/dialog/clonetiler.cpp
@@ -1107,7 +1107,7 @@ CloneTiler::CloneTiler (void) :
#endif
double value = prefs->getDouble(prefs_path + "fillwidth", 50.0);
- Inkscape::Util::Unit const unit = unit_menu->getUnit();
+ Inkscape::Util::Unit const *unit = unit_menu->getUnit();
gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit);
fill_width->set_value (units);
@@ -1140,7 +1140,7 @@ CloneTiler::CloneTiler (void) :
#endif
double value = prefs->getDouble(prefs_path + "fillheight", 50.0);
- Inkscape::Util::Unit const unit = unit_menu->getUnit();
+ Inkscape::Util::Unit const *unit = unit_menu->getUnit();
gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit);
fill_height->set_value (units);
@@ -2948,7 +2948,7 @@ void CloneTiler::clonetiler_switch_to_fill(GtkToggleButton * /*tb*/, GtkWidget *
void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u)
{
gdouble const raw_dist = gtk_adjustment_get_value (adj);
- Inkscape::Util::Unit const unit = u->getUnit();
+ Inkscape::Util::Unit const *unit = u->getUnit();
gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px");
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
@@ -2958,7 +2958,7 @@ void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, Inkscape::UI:
void CloneTiler::clonetiler_fill_height_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u)
{
gdouble const raw_dist = gtk_adjustment_get_value (adj);
- Inkscape::Util::Unit const unit = u->getUnit();
+ Inkscape::Util::Unit const *unit = u->getUnit();
gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px");
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
@@ -2971,7 +2971,7 @@ void CloneTiler::clonetiler_unit_changed()
gdouble width_pixels = prefs->getDouble(prefs_path + "fillwidth");
gdouble height_pixels = prefs->getDouble(prefs_path + "fillheight");
- Inkscape::Util::Unit unit = unit_menu->getUnit();
+ Inkscape::Util::Unit const *unit = unit_menu->getUnit();
gdouble width_value = Inkscape::Util::Quantity::convert(width_pixels, "px", unit);
gdouble height_value = Inkscape::Util::Quantity::convert(height_pixels, "px", unit);
diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp
index 37d0ce213..a6019c55c 100644
--- a/src/ui/dialog/document-properties.cpp
+++ b/src/ui/dialog/document-properties.cpp
@@ -1441,7 +1441,7 @@ void DocumentProperties::update()
_rum_deflt.setUnit (nv->doc_units->abbr);
double doc_w = sp_desktop_document(dt)->getRoot()->width.value;
- Glib::ustring doc_w_unit = unit_table.getUnit(sp_desktop_document(dt)->getRoot()->width.unit).abbr;
+ Glib::ustring doc_w_unit = unit_table.getUnit(sp_desktop_document(dt)->getRoot()->width.unit)->abbr;
if (doc_w_unit == "") {
doc_w_unit = "px";
} else if (doc_w_unit == "%" && sp_desktop_document(dt)->getRoot()->viewBox_set) {
@@ -1449,7 +1449,7 @@ void DocumentProperties::update()
doc_w = sp_desktop_document(dt)->getRoot()->viewBox.width();
}
double doc_h = sp_desktop_document(dt)->getRoot()->height.value;
- Glib::ustring doc_h_unit = unit_table.getUnit(sp_desktop_document(dt)->getRoot()->height.unit).abbr;
+ Glib::ustring doc_h_unit = unit_table.getUnit(sp_desktop_document(dt)->getRoot()->height.unit)->abbr;
if (doc_h_unit == "") {
doc_h_unit = "px";
} else if (doc_h_unit == "%" && sp_desktop_document(dt)->getRoot()->viewBox_set) {
@@ -1644,11 +1644,11 @@ void DocumentProperties::onDocUnitChange()
{
SPDocument *doc = SP_ACTIVE_DOCUMENT;
Inkscape::XML::Node *repr = sp_desktop_namedview(getDesktop())->getRepr();
- Inkscape::Util::Unit old_doc_unit = unit_table.getUnit("px");
+ Inkscape::Util::Unit const *old_doc_unit = unit_table.getUnit("px");
if(repr->attribute("inkscape:document-units")) {
old_doc_unit = unit_table.getUnit(repr->attribute("inkscape:document-units"));
}
- Inkscape::Util::Unit doc_unit = _rum_deflt.getUnit();
+ Inkscape::Util::Unit const *doc_unit = _rum_deflt.getUnit();
// Don't execute when change is being undone
if (!DocumentUndo::getUndoSensitive(doc)) {
@@ -1657,7 +1657,7 @@ void DocumentProperties::onDocUnitChange()
// Set document unit
Inkscape::SVGOStringStream os;
- os << doc_unit.abbr;
+ os << doc_unit->abbr;
repr->setAttribute("inkscape:document-units", os.str().c_str());
// Set viewBox
diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp
index 577793496..f1f7cf6c1 100644
--- a/src/ui/dialog/export.cpp
+++ b/src/ui/dialog/export.cpp
@@ -1884,7 +1884,7 @@ void Export::setValuePx(Glib::RefPtr<Gtk::Adjustment>& adj, double val)
void Export::setValuePx( Gtk::Adjustment *adj, double val)
#endif
{
- const Unit unit = unit_selector->getUnit();
+ Unit const *unit = unit_selector->getUnit();
setValue(adj, Inkscape::Util::Quantity::convert(val, "px", unit));
@@ -1934,7 +1934,7 @@ float Export::getValuePx( Gtk::Adjustment *adj )
#endif
{
float value = getValue( adj);
- const Unit unit = unit_selector->getUnit();
+ Unit const *unit = unit_selector->getUnit();
return Inkscape::Util::Quantity::convert(value, unit, "px");
} // end of sp_export_value_get_px()
diff --git a/src/ui/dialog/guides.cpp b/src/ui/dialog/guides.cpp
index 2de387364..5dfafa78d 100644
--- a/src/ui/dialog/guides.cpp
+++ b/src/ui/dialog/guides.cpp
@@ -59,7 +59,7 @@ Glib::ustring GuidelinePropertiesDialog::_angle_unit_status = DEG; // initialize
GuidelinePropertiesDialog::~GuidelinePropertiesDialog() {
// save current status
_relative_toggle_status = _relative_toggle.get_active();
- _angle_unit_status = _spin_angle.getUnit().abbr;
+ _angle_unit_status = _spin_angle.getUnit()->abbr;
}
void GuidelinePropertiesDialog::showDialog(SPGuide *guide, SPDesktop *desktop) {
diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp
index 82eb697bd..76ec68c3e 100644
--- a/src/ui/tool/node.cpp
+++ b/src/ui/tool/node.cpp
@@ -493,9 +493,9 @@ Glib::ustring Handle::_getDragTip(GdkEventMotion */*event*/) const
Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dist[Geom::X], "px");
Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dist[Geom::Y], "px");
Inkscape::Util::Quantity len_q = Inkscape::Util::Quantity(length(), "px");
- GString *x = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str());
- GString *y = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str());
- GString *len = g_string_new(len_q.string(*_desktop->namedview->doc_units).c_str());
+ GString *x = g_string_new(x_q.string(_desktop->namedview->doc_units).c_str());
+ GString *y = g_string_new(y_q.string(_desktop->namedview->doc_units).c_str());
+ GString *len = g_string_new(len_q.string(_desktop->namedview->doc_units).c_str());
Glib::ustring ret = format_tip(C_("Path handle tip",
"Move handle by %s, %s; angle %.2f°, length %s"), x->str, y->str, angle, len->str);
g_string_free(x, TRUE);
@@ -1300,10 +1300,9 @@ Glib::ustring Node::_getDragTip(GdkEventMotion */*event*/) const
Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dist[Geom::X], "px");
Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dist[Geom::Y], "px");
- GString *x = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str());
- GString *y = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str());
- Glib::ustring ret = format_tip(C_("Path node tip", "Move node by %s, %s"),
- x->str, y->str);
+ GString *x = g_string_new(x_q.string(_desktop->namedview->doc_units).c_str());
+ GString *y = g_string_new(y_q.string(_desktop->namedview->doc_units).c_str());
+ Glib::ustring ret = format_tip(C_("Path node tip", "Move node by %s, %s"), x->str, y->str);
g_string_free(x, TRUE);
g_string_free(y, TRUE);
return ret;
diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp
index 2379dc181..b13567adb 100644
--- a/src/ui/widget/page-sizer.cpp
+++ b/src/ui/widget/page-sizer.cpp
@@ -565,9 +565,8 @@ PageSizer::find_paper_size (Inkscape::Util::Quantity w, Inkscape::Util::Quantity
for (iter = _paperSizeTable.begin() ;
iter != _paperSizeTable.end() ; ++iter) {
PaperSize paper = iter->second;
- Inkscape::Util::Unit const &i_unit = paper.unit;
- double smallX = Inkscape::Util::Quantity::convert(paper.smaller, i_unit, *w.unit);
- double largeX = Inkscape::Util::Quantity::convert(paper.larger, i_unit, *w.unit);
+ double smallX = Inkscape::Util::Quantity::convert(paper.smaller, paper.unit, w.unit);
+ double largeX = Inkscape::Util::Quantity::convert(paper.larger, paper.unit, w.unit);
g_return_val_if_fail(smallX <= largeX, _paperSizeListStore->children().end());
@@ -704,7 +703,7 @@ void
PageSizer::on_value_changed()
{
if (_widgetRegistry->isUpdating()) return;
- if (_unit != _dimensionUnits.getUnit().abbr) return;
+ if (_unit != _dimensionUnits.getUnit()->abbr) return;
setDim (Inkscape::Util::Quantity(_dimensionWidth.getValue(""), _dimensionUnits.getUnit()),
Inkscape::Util::Quantity(_dimensionHeight.getValue(""), _dimensionUnits.getUnit()));
}
@@ -712,7 +711,7 @@ void
PageSizer::on_units_changed()
{
if (_widgetRegistry->isUpdating()) return;
- _unit = _dimensionUnits.getUnit().abbr;
+ _unit = _dimensionUnits.getUnit()->abbr;
setDim (Inkscape::Util::Quantity(_dimensionWidth.getValue(""), _dimensionUnits.getUnit()),
Inkscape::Util::Quantity(_dimensionHeight.getValue(""), _dimensionUnits.getUnit()));
}
diff --git a/src/ui/widget/page-sizer.h b/src/ui/widget/page-sizer.h
index 95836a005..dc8e34d82 100644
--- a/src/ui/widget/page-sizer.h
+++ b/src/ui/widget/page-sizer.h
@@ -64,7 +64,7 @@ public:
PaperSize(const Glib::ustring &nameArg,
double smallerArg,
double largerArg,
- Inkscape::Util::Unit unitArg)
+ Inkscape::Util::Unit const *unitArg)
{
name = nameArg;
smaller = smallerArg;
@@ -108,7 +108,7 @@ public:
/**
* The units (px, pt, mm, etc) of this specification
*/
- Inkscape::Util::Unit unit;
+ Inkscape::Util::Unit const *unit; /// pointer to object in UnitTable, do not delete
private:
diff --git a/src/ui/widget/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp
index 567f29f91..3ba00c083 100644
--- a/src/ui/widget/preferences-widget.cpp
+++ b/src/ui/widget/preferences-widget.cpp
@@ -354,7 +354,7 @@ void PrefSpinUnit::on_my_value_changed()
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
if (getWidget()->get_visible()) //only take action if user changed value
{
- prefs->setDoubleUnit(_prefs_path, getValue(getUnit().abbr), getUnit().abbr);
+ prefs->setDoubleUnit(_prefs_path, getValue(getUnit()->abbr), getUnit()->abbr);
}
}
diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h
index 93b0cef4e..883a9e1a2 100644
--- a/src/ui/widget/registered-widget.h
+++ b/src/ui/widget/registered-widget.h
@@ -167,7 +167,7 @@ public:
SPDocument *doc_in = NULL );
void setUnit (const Glib::ustring);
- Unit getUnit() const { return static_cast<UnitMenu*>(_widget)->getUnit(); };
+ Unit const * getUnit() const { return static_cast<UnitMenu*>(_widget)->getUnit(); };
UnitMenu* getUnitMenu() const { return static_cast<UnitMenu*>(_widget); };
sigc::connection _changed_connection;
diff --git a/src/ui/widget/scalar-unit.cpp b/src/ui/widget/scalar-unit.cpp
index 2f4c1f341..4fa1a7584 100644
--- a/src/ui/widget/scalar-unit.cpp
+++ b/src/ui/widget/scalar-unit.cpp
@@ -102,7 +102,7 @@ void ScalarUnit::resetUnitType(UnitType unit_type)
lastUnits = _unit_menu->getUnitAbbr();
}
-Unit ScalarUnit::getUnit() const
+Unit const * ScalarUnit::getUnit() const
{
g_assert(_unit_menu != NULL);
return _unit_menu->getUnit();
@@ -228,13 +228,13 @@ void ScalarUnit::on_unit_changed()
Glib::ustring abbr = _unit_menu->getUnitAbbr();
_suffix->set_label(abbr);
- Inkscape::Util::Unit new_unit = (unit_table.getUnit(abbr));
- Inkscape::Util::Unit old_unit = (unit_table.getUnit(lastUnits));
+ Inkscape::Util::Unit const *new_unit = unit_table.getUnit(abbr);
+ Inkscape::Util::Unit const *old_unit = unit_table.getUnit(lastUnits);
double convertedVal = 0;
- if (old_unit.type == UNIT_TYPE_DIMENSIONLESS && new_unit.type == UNIT_TYPE_LINEAR) {
+ if (old_unit->type == UNIT_TYPE_DIMENSIONLESS && new_unit->type == UNIT_TYPE_LINEAR) {
convertedVal = PercentageToAbsolute(Scalar::getValue());
- } else if (old_unit.type == UNIT_TYPE_LINEAR && new_unit.type == UNIT_TYPE_DIMENSIONLESS) {
+ } else if (old_unit->type == UNIT_TYPE_LINEAR && new_unit->type == UNIT_TYPE_DIMENSIONLESS) {
convertedVal = AbsoluteToPercentage(Scalar::getValue());
} else {
double conversion = _unit_menu->getConversion(lastUnits);
diff --git a/src/ui/widget/scalar-unit.h b/src/ui/widget/scalar-unit.h
index 4f22f438c..9e310d3bd 100644
--- a/src/ui/widget/scalar-unit.h
+++ b/src/ui/widget/scalar-unit.h
@@ -82,7 +82,7 @@ public:
/**
* Gets the object for the currently selected unit.
*/
- Unit getUnit() const;
+ Unit const * getUnit() const;
/**
* Gets the UnitType ID for the unit.
diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp
index 97581aa83..3a6b0c7df 100644
--- a/src/ui/widget/selected-style.cpp
+++ b/src/ui/widget/selected-style.cpp
@@ -315,8 +315,8 @@ SelectedStyle::SelectedStyle(bool /*layout*/)
Gtk::RadioMenuItem *mi = Gtk::manage(new Gtk::RadioMenuItem(_sw_group));
mi->add(*(new Gtk::Label(iter->first, 0.0, 0.5)));
_unit_mis = g_slist_append(_unit_mis, mi);
- Inkscape::Util::Unit const *u = new Inkscape::Util::Unit(unit_table.getUnit(iter->first));
- mi->signal_activate().connect(sigc::bind<Inkscape::Util::Unit>(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), *u));
+ Inkscape::Util::Unit const *u = unit_table.getUnit(iter->first);
+ mi->signal_activate().connect(sigc::bind<Inkscape::Util::Unit const *>(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), u));
_popup_sw.attach(*mi, 0,1, row, row+1);
row++;
++iter;
@@ -481,7 +481,7 @@ SelectedStyle::setDesktop(SPDesktop *desktop)
this )
));
- _sw_unit = const_cast<Inkscape::Util::Unit*>(sp_desktop_namedview(desktop)->doc_units);
+ _sw_unit = sp_desktop_namedview(desktop)->doc_units;
// Set the doc default unit active in the units list
gint length = g_slist_length(_unit_mis);
@@ -931,8 +931,8 @@ SelectedStyle::on_opacity_click(GdkEventButton *event)
return false;
}
-void SelectedStyle::on_popup_units(Inkscape::Util::Unit &unit) {
- _sw_unit = new Inkscape::Util::Unit(unit);
+void SelectedStyle::on_popup_units(Inkscape::Util::Unit const *unit) {
+ _sw_unit = unit;
update();
}
@@ -940,7 +940,7 @@ void SelectedStyle::on_popup_preset(int i) {
SPCSSAttr *css = sp_repr_css_attr_new ();
gdouble w;
if (_sw_unit) {
- w = Inkscape::Util::Quantity::convert(_sw_presets[i], *_sw_unit, "px");
+ w = Inkscape::Util::Quantity::convert(_sw_presets[i], _sw_unit, "px");
} else {
w = _sw_presets[i];
}
@@ -1119,7 +1119,7 @@ SelectedStyle::update()
{
double w;
if (_sw_unit) {
- w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", *_sw_unit);
+ w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", _sw_unit);
} else {
w = query->stroke_width.computed;
}
diff --git a/src/ui/widget/selected-style.h b/src/ui/widget/selected-style.h
index 0a907f1fd..21e5575ed 100644
--- a/src/ui/widget/selected-style.h
+++ b/src/ui/widget/selected-style.h
@@ -276,11 +276,11 @@ protected:
Gtk::Menu _popup_sw;
Gtk::RadioButtonGroup _sw_group;
GSList *_unit_mis;
- void on_popup_units(Inkscape::Util::Unit &u);
+ void on_popup_units(Inkscape::Util::Unit const *u);
void on_popup_preset(int i);
Gtk::MenuItem _popup_sw_remove;
- Inkscape::Util::Unit *_sw_unit;
+ Inkscape::Util::Unit const *_sw_unit; /// points to object in UnitTable, do not delete
void *_drop[2];
bool _dropEnabled[2];
diff --git a/src/ui/widget/spinbutton.cpp b/src/ui/widget/spinbutton.cpp
index 1114ff32b..6cbc15c1b 100644
--- a/src/ui/widget/spinbutton.cpp
+++ b/src/ui/widget/spinbutton.cpp
@@ -35,16 +35,16 @@ int SpinButton::on_input(double* newvalue)
try {
Inkscape::Util::EvaluatorQuantity result;
if (_unit_menu || _unit_tracker) {
- Unit unit;
+ Unit const *unit = NULL;
if (_unit_menu) {
unit = _unit_menu->getUnit();
} else {
unit = _unit_tracker->getActiveUnit();
}
- Inkscape::Util::ExpressionEvaluator eval = Inkscape::Util::ExpressionEvaluator(get_text().c_str(), &unit);
+ Inkscape::Util::ExpressionEvaluator eval = Inkscape::Util::ExpressionEvaluator(get_text().c_str(), unit);
result = eval.evaluate();
// check if output dimension corresponds to input unit
- if (result.dimension != (unit.isAbsolute() ? 1 : 0) ) {
+ if (result.dimension != (unit->isAbsolute() ? 1 : 0) ) {
throw Inkscape::Util::EvaluatorException("Input dimensions do not match with parameter dimensions.","");
}
} else {
diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp
index 49466ce54..a33c1d09f 100644
--- a/src/ui/widget/style-swatch.cpp
+++ b/src/ui/widget/style-swatch.cpp
@@ -333,7 +333,7 @@ void StyleSwatch::setStyle(SPStyle *query)
if (has_stroke) {
double w;
if (_sw_unit) {
- w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", *_sw_unit);
+ w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", _sw_unit);
} else {
w = query->stroke_width.computed;
}
diff --git a/src/ui/widget/unit-menu.cpp b/src/ui/widget/unit-menu.cpp
index 684016471..7416a2f02 100644
--- a/src/ui/widget/unit-menu.cpp
+++ b/src/ui/widget/unit-menu.cpp
@@ -56,7 +56,7 @@ void UnitMenu::addUnit(Unit const& u)
append(u.abbr);
}
-Unit UnitMenu::getUnit() const
+Unit const * UnitMenu::getUnit() const
{
if (get_active_text() == "") {
g_assert(_type != UNIT_TYPE_NONE);
@@ -79,27 +79,27 @@ Glib::ustring UnitMenu::getUnitAbbr() const
if (get_active_text() == "") {
return "";
}
- return getUnit().abbr;
+ return getUnit()->abbr;
}
UnitType UnitMenu::getUnitType() const
{
- return getUnit().type;
+ return getUnit()->type;
}
double UnitMenu::getUnitFactor() const
{
- return getUnit().factor;
+ return getUnit()->factor;
}
int UnitMenu::getDefaultDigits() const
{
- return getUnit().defaultDigits();
+ return getUnit()->defaultDigits();
}
double UnitMenu::getDefaultStep() const
{
- int factor_digits = -1*int(log10(getUnit().factor));
+ int factor_digits = -1*int(log10(getUnit()->factor));
return pow(10.0, factor_digits);
}
@@ -110,19 +110,20 @@ double UnitMenu::getDefaultPage() const
double UnitMenu::getConversion(Glib::ustring const &new_unit_abbr, Glib::ustring const &old_unit_abbr) const
{
- double old_factor = getUnit().factor;
- if (old_unit_abbr != "no_unit")
- old_factor = unit_table.getUnit(old_unit_abbr).factor;
- Unit new_unit = unit_table.getUnit(new_unit_abbr);
+ double old_factor = getUnit()->factor;
+ if (old_unit_abbr != "no_unit") {
+ old_factor = unit_table.getUnit(old_unit_abbr)->factor;
+ }
+ Unit const * new_unit = unit_table.getUnit(new_unit_abbr);
// Catch the case of zero or negative unit factors (error!)
if (old_factor < 0.0000001 ||
- new_unit.factor < 0.0000001) {
+ new_unit->factor < 0.0000001) {
// TODO: Should we assert here?
return 0.00;
}
- return old_factor / new_unit.factor;
+ return old_factor / new_unit->factor;
}
bool UnitMenu::isAbsolute() const
diff --git a/src/ui/widget/unit-menu.h b/src/ui/widget/unit-menu.h
index 3f4df6bf9..114c536c9 100644
--- a/src/ui/widget/unit-menu.h
+++ b/src/ui/widget/unit-menu.h
@@ -74,7 +74,7 @@ public:
* Returns the Unit object corresponding to the current selection
* in the dropdown widget.
*/
- Unit getUnit() const;
+ Unit const * getUnit() const;
/**
* Returns the abbreviated unit name of the selected unit.
diff --git a/src/ui/widget/unit-tracker.cpp b/src/ui/widget/unit-tracker.cpp
index 155f3fafe..67eb1f48d 100644
--- a/src/ui/widget/unit-tracker.cpp
+++ b/src/ui/widget/unit-tracker.cpp
@@ -27,6 +27,7 @@ namespace Widget {
UnitTracker::UnitTracker(UnitType unit_type) :
_active(0),
_isUpdating(false),
+ _activeUnit(NULL),
_activeUnitInitialized(false),
_store(0),
_unitList(0),
@@ -74,7 +75,7 @@ bool UnitTracker::isUpdating() const
return _isUpdating;
}
-Inkscape::Util::Unit UnitTracker::getActiveUnit() const
+Inkscape::Util::Unit const * UnitTracker::getActiveUnit() const
{
return _activeUnit;
}
@@ -101,8 +102,8 @@ void UnitTracker::setActiveUnit(Inkscape::Util::Unit const *unit)
void UnitTracker::setActiveUnitByAbbr(gchar const *abbr)
{
- Inkscape::Util::Unit u = unit_table.getUnit(abbr);
- setActiveUnit(&u);
+ Inkscape::Util::Unit const *u = unit_table.getUnit(abbr);
+ setActiveUnit(u);
}
void UnitTracker::addAdjustment(GtkAdjustment *adj)
@@ -113,11 +114,11 @@ void UnitTracker::addAdjustment(GtkAdjustment *adj)
}
}
-void UnitTracker::addUnit(Inkscape::Util::Unit const &u)
+void UnitTracker::addUnit(Inkscape::Util::Unit const *u)
{
GtkTreeIter iter;
gtk_list_store_append(_store, &iter);
- gtk_list_store_set(_store, &iter, COLUMN_STRING, u.abbr.c_str(), -1);
+ gtk_list_store_set(_store, &iter, COLUMN_STRING, u ? u->abbr.c_str() : "NULL", -1);
}
void UnitTracker::setFullVal(GtkAdjustment *adj, gdouble val)
@@ -197,13 +198,13 @@ void UnitTracker::_setActive(gint active)
if (found) {
gchar *abbr;
gtk_tree_model_get(GTK_TREE_MODEL(_store), &iter, COLUMN_STRING, &abbr, -1);
- Inkscape::Util::Unit unit = unit_table.getUnit(abbr);
+ Inkscape::Util::Unit const *unit = unit_table.getUnit(abbr);
found = gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(_store), &iter, NULL, active);
if (found) {
gchar *newAbbr;
gtk_tree_model_get(GTK_TREE_MODEL(_store), &iter, COLUMN_STRING, &newAbbr, -1);
- Inkscape::Util::Unit newUnit = unit_table.getUnit(newAbbr);
+ Inkscape::Util::Unit const *newUnit = unit_table.getUnit(newAbbr);
_activeUnit = newUnit;
if (_adjList) {
@@ -230,7 +231,7 @@ void UnitTracker::_setActive(gint active)
}
}
-void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const oldUnit, Inkscape::Util::Unit const newUnit)
+void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const *oldUnit, Inkscape::Util::Unit const *newUnit)
{
_isUpdating = true;
for ( GSList *cur = _adjList ; cur ; cur = g_slist_next(cur) ) {
@@ -238,13 +239,13 @@ void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const oldUnit, Inkscape
gdouble oldVal = gtk_adjustment_get_value(adj);
gdouble val = oldVal;
- if ( (oldUnit.type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS)
- && (newUnit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) )
+ if ( (oldUnit->type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS)
+ && (newUnit->type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) )
{
- val = newUnit.factor * 100;
+ val = newUnit->factor * 100;
_priorValues[adj] = Inkscape::Util::Quantity::convert(oldVal, oldUnit, "px");
- } else if ( (oldUnit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS)
- && (newUnit.type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) )
+ } else if ( (oldUnit->type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS)
+ && (newUnit->type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) )
{
if (_priorValues.find(adj) != _priorValues.end()) {
val = Inkscape::Util::Quantity::convert(_priorValues[adj], "px", newUnit);
diff --git a/src/ui/widget/unit-tracker.h b/src/ui/widget/unit-tracker.h
index 19559ae1c..61bb556ef 100644
--- a/src/ui/widget/unit-tracker.h
+++ b/src/ui/widget/unit-tracker.h
@@ -36,9 +36,9 @@ public:
void setActiveUnit(Inkscape::Util::Unit const *unit);
void setActiveUnitByAbbr(gchar const *abbr);
- Inkscape::Util::Unit getActiveUnit() const;
+ Inkscape::Util::Unit const * getActiveUnit() const;
- void addUnit(Inkscape::Util::Unit const &u);
+ void addUnit(Inkscape::Util::Unit const *u);
void addAdjustment(GtkAdjustment *adj);
void setFullVal(GtkAdjustment *adj, gdouble val);
@@ -52,13 +52,13 @@ private:
static void _actionFinalizedCB(gpointer data, GObject *where_the_object_was);
static void _adjustmentFinalizedCB(gpointer data, GObject *where_the_object_was);
void _setActive(gint index);
- void _fixupAdjustments(Inkscape::Util::Unit const oldUnit, Inkscape::Util::Unit const newUnit);
+ void _fixupAdjustments(Inkscape::Util::Unit const *oldUnit, Inkscape::Util::Unit const *newUnit);
void _actionFinalized(GObject *where_the_object_was);
void _adjustmentFinalized(GObject *where_the_object_was);
gint _active;
bool _isUpdating;
- Inkscape::Util::Unit _activeUnit;
+ Inkscape::Util::Unit const *_activeUnit;
bool _activeUnitInitialized;
GtkListStore *_store;
GSList *_unitList;
diff --git a/src/util/expression-evaluator.cpp b/src/util/expression-evaluator.cpp
index 3b7e77c6c..48064e647 100644
--- a/src/util/expression-evaluator.cpp
+++ b/src/util/expression-evaluator.cpp
@@ -48,7 +48,7 @@ EvaluatorToken::EvaluatorToken()
value.fl = 0;
}
-ExpressionEvaluator::ExpressionEvaluator(const char *string, Unit *unit) :
+ExpressionEvaluator::ExpressionEvaluator(const char *string, Unit const *unit) :
string(string),
unit(unit)
{
@@ -360,7 +360,7 @@ int ExpressionEvaluator::getIdentifierSize(const char *string, int start_offset)
bool ExpressionEvaluator::resolveUnit (const char* identifier,
EvaluatorQuantity *result,
- Unit* unit)
+ Unit const* unit)
{
if (!unit) {
result->value = 1;
@@ -371,9 +371,9 @@ bool ExpressionEvaluator::resolveUnit (const char* identifier,
result->dimension = unit->isAbsolute() ? 1 : 0;
return true;
} else if (unit_table.hasUnit(identifier)) {
- Unit identifier_unit = unit_table.getUnit(identifier);
- result->value = Quantity::convert(1, *unit, identifier_unit);
- result->dimension = identifier_unit.isAbsolute() ? 1 : 0;
+ Unit const *identifier_unit = unit_table.getUnit(identifier);
+ result->value = Quantity::convert(1, unit, identifier_unit);
+ result->dimension = identifier_unit->isAbsolute() ? 1 : 0;
return true;
} else {
return false;
diff --git a/src/util/expression-evaluator.h b/src/util/expression-evaluator.h
index 6412dfea7..50ff3fb70 100644
--- a/src/util/expression-evaluator.h
+++ b/src/util/expression-evaluator.h
@@ -133,13 +133,13 @@ public:
class ExpressionEvaluator
{
public:
- ExpressionEvaluator(const char *string, Unit *unit = NULL);
+ ExpressionEvaluator(const char *string, Unit const *unit = NULL);
EvaluatorQuantity evaluate();
private:
const char *string;
- Unit *unit;
+ Unit const *unit;
EvaluatorToken current_token;
const char *start_of_current_token;
@@ -160,7 +160,7 @@ private:
static bool isUnitIdentifierStart(gunichar c);
static int getIdentifierSize(const char *s, int start);
- static bool resolveUnit(const char *identifier, EvaluatorQuantity *result, Unit *unit);
+ static bool resolveUnit(const char *identifier, EvaluatorQuantity *result, Unit const *unit);
void throwError(const char *msg);
};
diff --git a/src/util/units.cpp b/src/util/units.cpp
index cabbc044d..1023cfb6e 100644
--- a/src/util/units.cpp
+++ b/src/util/units.cpp
@@ -189,15 +189,15 @@ int Unit::defaultDigits() const
return factor_digits;
}
-bool Unit::compatibleWith(Unit const &u) const
+bool Unit::compatibleWith(Unit const *u) const
{
// Percentages
- if (type == UNIT_TYPE_DIMENSIONLESS || u.type == UNIT_TYPE_DIMENSIONLESS) {
+ if (type == UNIT_TYPE_DIMENSIONLESS || u->type == UNIT_TYPE_DIMENSIONLESS) {
return true;
}
// Other units with same type
- if (type == u.type) {
+ if (type == u->type) {
return true;
}
@@ -254,30 +254,30 @@ void UnitTable::addUnit(Unit const &u, bool primary)
}
}
-Unit const &UnitTable::getUnit(char const *abbr) const
+Unit const *UnitTable::getUnit(char const *abbr) const
{
UnitCodeMap::const_iterator f = _unit_map.find(make_unit_code(abbr));
if (f != _unit_map.end()) {
- return *f->second;
+ return &(*f->second);
}
- return _empty_unit;
+ return &_empty_unit;
}
-Unit const &UnitTable::getUnit(Glib::ustring const &unit_abbr) const
+Unit const *UnitTable::getUnit(Glib::ustring const &unit_abbr) const
{
return getUnit(unit_abbr.c_str());
}
-Unit const &UnitTable::getUnit(SVGLength::Unit u) const
+Unit const *UnitTable::getUnit(SVGLength::Unit u) const
{
if (u == 0 || u > SVGLength::LAST_UNIT) {
- return _empty_unit;
+ return &_empty_unit;
}
UnitCodeMap::const_iterator f = _unit_map.find(svg_length_lookup[u]);
if (f != _unit_map.end()) {
- return *f->second;
+ return &(*f->second);
}
- return _empty_unit;
+ return &_empty_unit;
}
Quantity UnitTable::parseQuantity(Glib::ustring const &q) const
@@ -303,6 +303,7 @@ Quantity UnitTable::parseQuantity(Glib::ustring const &q) const
return qty;
}
+/* UNSAFE while passing around pointers to the Unit objects in this table
bool UnitTable::deleteUnit(Unit const &u)
{
bool deleted = false;
@@ -318,6 +319,7 @@ bool UnitTable::deleteUnit(Unit const &u)
}
return deleted;
}
+*/
bool UnitTable::hasUnit(Glib::ustring const &unit) const
{
@@ -418,23 +420,23 @@ void UnitParser::on_end_element(Ctx &ctx, Glib::ustring const &name)
}
}
-Quantity::Quantity(double q, Unit const &u)
+Quantity::Quantity(double q, Unit const *u)
+ : unit(u)
+ , quantity(q)
{
- unit = new Unit(u);
- quantity = q;
}
Quantity::Quantity(double q, Glib::ustring const &u)
+ : unit(unit_table.getUnit(u.c_str()))
+ , quantity(q)
{
- unit = new Unit(unit_table.getUnit(u.c_str()));
- quantity = q;
}
Quantity::Quantity(double q, char const *u)
+ : unit(unit_table.getUnit(u))
+ , quantity(q)
{
- unit = new Unit(unit_table.getUnit(u));
- quantity = q;
}
-bool Quantity::compatibleWith(Unit const &u) const
+bool Quantity::compatibleWith(Unit const *u) const
{
return unit->compatibleWith(u);
}
@@ -447,9 +449,9 @@ bool Quantity::compatibleWith(char const *u) const
return compatibleWith(unit_table.getUnit(u));
}
-double Quantity::value(Unit const &u) const
+double Quantity::value(Unit const *u) const
{
- return convert(quantity, *unit, u);
+ return convert(quantity, unit, u);
}
double Quantity::value(Glib::ustring const &u) const
{
@@ -460,36 +462,36 @@ double Quantity::value(char const *u) const
return value(unit_table.getUnit(u));
}
-Glib::ustring Quantity::string(Unit const &u) const {
+Glib::ustring Quantity::string(Unit const *u) const {
return Glib::ustring::format(std::fixed, std::setprecision(2), value(u)) + " " + unit->abbr;
}
Glib::ustring Quantity::string(Glib::ustring const &u) const {
return string(unit_table.getUnit(u.c_str()));
}
Glib::ustring Quantity::string() const {
- return string(*unit);
+ return string(unit);
}
-double Quantity::convert(double from_dist, Unit const &from, Unit const &to)
+double Quantity::convert(double from_dist, Unit const *from, Unit const *to)
{
// Percentage
- if (to.type == UNIT_TYPE_DIMENSIONLESS) {
- return from_dist * to.factor;
+ if (to->type == UNIT_TYPE_DIMENSIONLESS) {
+ return from_dist * to->factor;
}
// Incompatible units
- if (from.type != to.type) {
+ if (from->type != to->type) {
return -1;
}
// Compatible units
- return from_dist * from.factor / to.factor;
+ return from_dist * from->factor / to->factor;
}
-double Quantity::convert(double from_dist, Glib::ustring const &from, Unit const &to)
+double Quantity::convert(double from_dist, Glib::ustring const &from, Unit const *to)
{
return convert(from_dist, unit_table.getUnit(from.c_str()), to);
}
-double Quantity::convert(double from_dist, Unit const &from, Glib::ustring const &to)
+double Quantity::convert(double from_dist, Unit const *from, Glib::ustring const &to)
{
return convert(from_dist, from, unit_table.getUnit(to.c_str()));
}
@@ -508,7 +510,7 @@ bool Quantity::operator<(Quantity const &other) const
g_warning("Incompatible units");
return false;
}
- return quantity < other.value(*unit);
+ return quantity < other.value(unit);
}
bool Quantity::operator==(Quantity const &other) const
{
diff --git a/src/util/units.h b/src/util/units.h
index 7566715d8..e1addaa24 100644
--- a/src/util/units.h
+++ b/src/util/units.h
@@ -58,7 +58,7 @@ public:
int defaultDigits() const;
/** Checks if a unit is compatible with the specified unit. */
- bool compatibleWith(Unit const &u) const;
+ bool compatibleWith(Unit const *u) const;
bool compatibleWith(Glib::ustring const &) const;
bool compatibleWith(char const *) const;
@@ -84,29 +84,30 @@ public:
double quantity;
/** Initialize a quantity. */
- Quantity(double q, Unit const &u);
+ Quantity(double q, Unit const *u);
Quantity(double q, Glib::ustring const &u);
Quantity(double q, char const *u);
/** Checks if a quantity is compatible with the specified unit. */
- bool compatibleWith(Unit const &u) const;
+ bool compatibleWith(Unit const *u) const;
bool compatibleWith(Glib::ustring const &u) const;
bool compatibleWith(char const *u) const;
/** Return the quantity's value in the specified unit. */
- double value(Unit const &u) const;
+ double value(Unit const *u) const;
double value(Glib::ustring const &u) const;
double value(char const *u) const;
/** Return a printable string of the value in the specified unit. */
- Glib::ustring string(Unit const &u) const;
+ Glib::ustring string(Unit const *u) const;
Glib::ustring string(Glib::ustring const &u) const;
Glib::ustring string() const;
- /** Convert distances. */
- static double convert(double from_dist, Unit const &from, Unit const &to);
- static double convert(double from_dist, Glib::ustring const &from, Unit const &to);
- static double convert(double from_dist, Unit const &from, Glib::ustring const &to);
+ /** Convert distances.
+ no NULL check is performed on the passed pointers to Unit objects! */
+ static double convert(double from_dist, Unit const *from, Unit const *to);
+ static double convert(double from_dist, Glib::ustring const &from, Unit const *to);
+ static double convert(double from_dist, Unit const *from, Glib::ustring const &to);
static double convert(double from_dist, Glib::ustring const &from, Glib::ustring const &to);
static double convert(double from_dist, char const *from, char const *to);
@@ -132,17 +133,18 @@ public:
void addUnit(Unit const &u, bool primary);
/** Retrieve a given unit based on its string identifier */
- Unit const &getUnit(Glib::ustring const &name) const;
- Unit const &getUnit(char const *name) const;
+ Unit const *getUnit(Glib::ustring const &name) const;
+ Unit const *getUnit(char const *name) const;
/** Retrieve a given unit based on its SVGLength unit */
- Unit const &getUnit(SVGLength::Unit u) const;
+ Unit const *getUnit(SVGLength::Unit u) const;
/** Retrieve a quantity based on its string identifier */
Quantity parseQuantity(Glib::ustring const &q) const;
- /** Remove a unit definition from the given unit type table */
- bool deleteUnit(Unit const &u);
+ /** Remove a unit definition from the given unit type table * /
+ * DISABLED, unsafe with the current passing around pointers to Unit objects in this table */
+ //bool deleteUnit(Unit const &u);
/** Returns true if the given string 'name' is a valid unit in the table */
bool hasUnit(Glib::ustring const &name) const;
diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp
index e9a834db7..3ca433586 100644
--- a/src/widgets/desktop-widget.cpp
+++ b/src/widgets/desktop-widget.cpp
@@ -394,9 +394,9 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw )
GtkWidget *eventbox = gtk_event_box_new ();
dtw->hruler = sp_ruler_new(GTK_ORIENTATION_HORIZONTAL);
dtw->hruler_box = eventbox;
- Inkscape::Util::Unit pt = unit_table.getUnit("pt");
+ Inkscape::Util::Unit const *pt = unit_table.getUnit("pt");
sp_ruler_set_unit(SP_RULER(dtw->hruler), pt);
- gtk_widget_set_tooltip_text (dtw->hruler_box, gettext(pt.name_plural.c_str()));
+ gtk_widget_set_tooltip_text (dtw->hruler_box, gettext(pt->name_plural.c_str()));
gtk_container_add (GTK_CONTAINER (eventbox), dtw->hruler);
g_signal_connect (G_OBJECT (eventbox), "button_press_event", G_CALLBACK (sp_dt_hruler_event), dtw);
g_signal_connect (G_OBJECT (eventbox), "button_release_event", G_CALLBACK (sp_dt_hruler_event), dtw);
@@ -425,7 +425,7 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw )
dtw->vruler = sp_ruler_new(GTK_ORIENTATION_VERTICAL);
dtw->vruler_box = eventbox;
sp_ruler_set_unit (SP_RULER (dtw->vruler), pt);
- gtk_widget_set_tooltip_text (dtw->vruler_box, gettext(pt.name_plural.c_str()));
+ gtk_widget_set_tooltip_text (dtw->vruler_box, gettext(pt->name_plural.c_str()));
gtk_container_add (GTK_CONTAINER (eventbox), GTK_WIDGET (dtw->vruler));
#if GTK_CHECK_VERSION(3,0,0)
diff --git a/src/widgets/lpe-toolbar.cpp b/src/widgets/lpe-toolbar.cpp
index 922526a9f..045d7aa78 100644
--- a/src/widgets/lpe-toolbar.cpp
+++ b/src/widgets/lpe-toolbar.cpp
@@ -198,9 +198,9 @@ static void lpetool_toggle_show_measuring_info(GtkToggleAction *act, GObject *tb
static void lpetool_unit_changed(GtkAction* /*act*/, GObject* tbl)
{
UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(tbl, "tracker"));
- Unit const unit = tracker->getActiveUnit();
+ Unit const *unit = tracker->getActiveUnit();
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- prefs->setString("/tools/lpetool/unit", unit.abbr);
+ prefs->setString("/tools/lpetool/unit", unit->abbr);
SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));
if (SP_IS_LPETOOL_CONTEXT(desktop->event_context)) {
@@ -299,10 +299,10 @@ void sp_lpetool_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GO
UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR);
tracker->setActiveUnit(sp_desktop_namedview(desktop)->doc_units);
g_object_set_data(holder, "tracker", tracker);
- Unit const unit = tracker->getActiveUnit();
+ Unit const *unit = tracker->getActiveUnit();
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- prefs->setString("/tools/lpetool/unit", unit.abbr);
+ prefs->setString("/tools/lpetool/unit", unit->abbr);
/** Automatically create a list of LPEs that get added to the toolbar **/
{
diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp
index 53ed2d275..58244566d 100644
--- a/src/widgets/measure-toolbar.cpp
+++ b/src/widgets/measure-toolbar.cpp
@@ -82,7 +82,7 @@ sp_measure_fontsize_value_changed(GtkAdjustment *adj, GObject *tbl)
static void measure_unit_changed(GtkAction* /*act*/, GObject* tbl)
{
UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(tbl, "tracker"));
- Glib::ustring const unit = tracker->getActiveUnit().abbr;
+ Glib::ustring const unit = tracker->getActiveUnit()->abbr;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setString("/tools/measure/unit", unit);
}
diff --git a/src/widgets/node-toolbar.cpp b/src/widgets/node-toolbar.cpp
index 2348acc46..0d4868642 100644
--- a/src/widgets/node-toolbar.cpp
+++ b/src/widgets/node-toolbar.cpp
@@ -240,7 +240,7 @@ static void sp_node_toolbox_coord_changed(gpointer /*shape_editor*/, GObject *tb
if (!tracker) {
return;
}
- Unit const unit = tracker->getActiveUnit();
+ Unit const *unit = tracker->getActiveUnit();
InkNodeTool *nt = get_node_tool();
if (!nt || nt->_selected_nodes->empty()) {
@@ -274,7 +274,7 @@ static void sp_node_path_value_changed(GtkAdjustment *adj, GObject *tbl, Geom::D
if (!tracker) {
return;
}
- Unit const unit = tracker->getActiveUnit();
+ Unit const *unit = tracker->getActiveUnit();
if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) {
prefs->setDouble(Glib::ustring("/tools/nodes/") + (d == Geom::X ? "x" : "y"),
diff --git a/src/widgets/paintbucket-toolbar.cpp b/src/widgets/paintbucket-toolbar.cpp
index 028753b59..363fadd3d 100644
--- a/src/widgets/paintbucket-toolbar.cpp
+++ b/src/widgets/paintbucket-toolbar.cpp
@@ -98,13 +98,13 @@ static void paintbucket_autogap_changed(EgeSelectOneAction* act, GObject * /*tbl
static void paintbucket_offset_changed(GtkAdjustment *adj, GObject *tbl)
{
UnitTracker* tracker = static_cast<UnitTracker*>(g_object_get_data( tbl, "tracker" ));
- Unit const unit = tracker->getActiveUnit();
+ Unit const *unit = tracker->getActiveUnit();
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
// Don't adjust the offset value because we're saving the
// unit and it'll be correctly handled on load.
prefs->setDouble("/tools/paintbucket/offset", (gdouble)gtk_adjustment_get_value(adj));
- prefs->setString("/tools/paintbucket/offsetunits", unit.abbr);
+ prefs->setString("/tools/paintbucket/offsetunits", unit->abbr);
}
static void paintbucket_defaults(GtkWidget *, GObject *tbl)
@@ -179,8 +179,8 @@ void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions
UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR);
Glib::ustring stored_unit = prefs->getString("/tools/paintbucket/offsetunits");
if (!stored_unit.empty()) {
- Unit u = unit_table.getUnit(stored_unit);
- tracker->setActiveUnit(&u);
+ Unit const *u = unit_table.getUnit(stored_unit);
+ tracker->setActiveUnit(u);
}
g_object_set_data( holder, "tracker", tracker );
{
diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp
index 0d5d3a688..0287a9aeb 100644
--- a/src/widgets/rect-toolbar.cpp
+++ b/src/widgets/rect-toolbar.cpp
@@ -93,7 +93,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *
SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));
UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data( tbl, "tracker" ));
- Unit const unit = tracker->getActiveUnit();
+ Unit const *unit = tracker->getActiveUnit();
if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
@@ -114,7 +114,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *
for (GSList const *items = selection->itemList(); items != NULL; items = items->next) {
if (SP_IS_RECT(items->data)) {
if (gtk_adjustment_get_value(adj) != 0) {
- (SP_RECT(items->data)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, *sp_desktop_namedview(desktop)->doc_units));
+ (SP_RECT(items->data)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, sp_desktop_namedview(desktop)->doc_units));
} else {
SP_OBJECT(items->data)->getRepr()->setAttribute(value_name, NULL);
}
@@ -185,8 +185,8 @@ static void rect_tb_event_attr_changed(Inkscape::XML::Node * /*repr*/, gchar con
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
UnitTracker* tracker = reinterpret_cast<UnitTracker*>( g_object_get_data( tbl, "tracker" ) );
- Unit const unit = tracker->getActiveUnit();
- Unit const doc_unit = *sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units;
+ Unit const *unit = tracker->getActiveUnit();
+ Unit const *doc_unit = sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units;
gpointer item = g_object_get_data( tbl, "item" );
if (item && SP_IS_RECT(item)) {
diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp
index e4e72d86e..2604ebf22 100644
--- a/src/widgets/ruler.cpp
+++ b/src/widgets/ruler.cpp
@@ -63,7 +63,7 @@ enum {
typedef struct
{
GtkOrientation orientation;
- Inkscape::Util::Unit *unit;
+ Inkscape::Util::Unit const *unit;
gdouble lower;
gdouble upper;
gdouble position;
@@ -260,7 +260,7 @@ sp_ruler_init (SPRuler *ruler)
gtk_widget_set_has_window (GTK_WIDGET (ruler), FALSE);
priv->orientation = GTK_ORIENTATION_HORIZONTAL;
- priv->unit = new Inkscape::Util::Unit(unit_table.getUnit("px"));
+ priv->unit = unit_table.getUnit("px");
priv->lower = 0;
priv->upper = 0;
priv->position = 0;
@@ -1071,15 +1071,15 @@ sp_ruler_remove_track_widget (SPRuler *ruler,
*/
void
sp_ruler_set_unit (SPRuler *ruler,
- const Inkscape::Util::Unit &unit)
+ Inkscape::Util::Unit const *unit)
{
SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler);
g_return_if_fail (SP_IS_RULER (ruler));
- if (*priv->unit != unit)
+ if (*priv->unit != *unit)
{
- priv->unit = new Inkscape::Util::Unit(unit);
+ priv->unit = unit;
g_object_notify(G_OBJECT(ruler), "unit");
gtk_widget_queue_draw (GTK_WIDGET (ruler));
@@ -1092,7 +1092,7 @@ sp_ruler_set_unit (SPRuler *ruler,
*
* Return value: the unit currently used in the @ruler widget.
**/
-Inkscape::Util::Unit*
+Inkscape::Util::Unit const*
sp_ruler_get_unit (SPRuler *ruler)
{
return SP_RULER_GET_PRIVATE (ruler)->unit;
@@ -1182,7 +1182,7 @@ sp_ruler_draw_ticks (SPRuler *ruler)
gint text_size;
gint pos;
gdouble max_size;
- Inkscape::Util::Unit *unit;
+ Inkscape::Util::Unit const *unit = NULL;
SPRulerMetric ruler_metric = ruler_metric_general; /* The metric to use for this unit system */
PangoLayout *layout;
PangoRectangle logical_rect, ink_rect;
@@ -1298,7 +1298,7 @@ sp_ruler_draw_ticks (SPRuler *ruler)
/* Inkscape change to ruler: Use a 1,2,4,8... scale for inches
* or a 1,2,5,10... scale for everything else */
- if (*sp_ruler_get_unit (ruler) == unit_table.getUnit("in"))
+ if (*sp_ruler_get_unit (ruler) == *unit_table.getUnit("in"))
ruler_metric = ruler_metric_inches;
for (scale = 0; scale < G_N_ELEMENTS (ruler_metric.ruler_scale); scale++)
@@ -1317,7 +1317,7 @@ sp_ruler_draw_ticks (SPRuler *ruler)
gdouble subd_incr;
/* hack to get proper subdivisions at full pixels */
- if (*unit == unit_table.getUnit("px") && scale == 1 && i == 1)
+ if (*unit == *unit_table.getUnit("px") && scale == 1 && i == 1)
subd_incr = 1.0;
else
subd_incr = ((gdouble) ruler_metric.ruler_scale[scale] /
diff --git a/src/widgets/ruler.h b/src/widgets/ruler.h
index 08760f584..ed529d082 100644
--- a/src/widgets/ruler.h
+++ b/src/widgets/ruler.h
@@ -56,8 +56,8 @@ void sp_ruler_remove_track_widget (SPRuler *ruler,
GtkWidget *widget);
void sp_ruler_set_unit (SPRuler *ruler,
- const Inkscape::Util::Unit &unit);
-Inkscape::Util::Unit *sp_ruler_get_unit (SPRuler *ruler);
+ const Inkscape::Util::Unit *unit);
+Inkscape::Util::Unit const * sp_ruler_get_unit (SPRuler *ruler);
void sp_ruler_set_position (SPRuler *ruler,
gdouble set_position);
gdouble sp_ruler_get_position (SPRuler *ruler);
diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp
index 590b0867f..58d7134b3 100644
--- a/src/widgets/select-toolbar.cpp
+++ b/src/widgets/select-toolbar.cpp
@@ -80,7 +80,7 @@ sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel)
Geom::OptRect const bbox(sel->bounds(bbox_type));
if ( bbox ) {
UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(G_OBJECT(spw), "tracker"));
- Unit const unit = tracker->getActiveUnit();
+ Unit const *unit = tracker->getActiveUnit();
struct { char const *key; double val; } const keyval[] = {
{ "X", bbox->min()[X] },
@@ -89,8 +89,8 @@ sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel)
{ "height", bbox->dimensions()[Y] }
};
- if (unit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) {
- double const val = unit.factor * 100;
+ if (unit->type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) {
+ double const val = unit->factor * 100;
for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) {
GtkAdjustment *a = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(spw), keyval[i].key));
gtk_adjustment_set_value(a, val);
@@ -185,14 +185,14 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
gdouble y1 = 0;
gdouble xrel = 0;
gdouble yrel = 0;
- Unit const unit = tracker->getActiveUnit();
+ Unit const *unit = tracker->getActiveUnit();
GtkAdjustment* a_x = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "X" ) );
GtkAdjustment* a_y = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "Y" ) );
GtkAdjustment* a_w = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "width" ) );
GtkAdjustment* a_h = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "height" ) );
- if (unit.type == Inkscape::Util::UNIT_TYPE_LINEAR) {
+ if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) {
x0 = Quantity::convert(gtk_adjustment_get_value(a_x), unit, "px");
y0 = Quantity::convert(gtk_adjustment_get_value(a_y), unit, "px");
x1 = x0 + Quantity::convert(gtk_adjustment_get_value(a_w), unit, "px");
@@ -200,13 +200,13 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
y1 = y0 + Quantity::convert(gtk_adjustment_get_value(a_h), unit, "px");;
yrel = Quantity::convert(gtk_adjustment_get_value(a_h), unit, "px") / bbox_user->dimensions()[Geom::Y];
} else {
- double const x0_propn = gtk_adjustment_get_value (a_x) / 100 / unit.factor;
+ double const x0_propn = gtk_adjustment_get_value (a_x) / 100 / unit->factor;
x0 = bbox_user->min()[Geom::X] * x0_propn;
- double const y0_propn = gtk_adjustment_get_value (a_y) / 100 / unit.factor;
+ double const y0_propn = gtk_adjustment_get_value (a_y) / 100 / unit->factor;
y0 = y0_propn * bbox_user->min()[Geom::Y];
- xrel = gtk_adjustment_get_value (a_w) / (100 / unit.factor);
+ xrel = gtk_adjustment_get_value (a_w) / (100 / unit->factor);
x1 = x0 + xrel * bbox_user->dimensions()[Geom::X];
- yrel = gtk_adjustment_get_value (a_h) / (100 / unit.factor);
+ yrel = gtk_adjustment_get_value (a_h) / (100 / unit->factor);
y1 = y0 + yrel * bbox_user->dimensions()[Geom::Y];
}
@@ -227,7 +227,7 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
double sv = fabs(y1 - bbox_user->max()[Geom::Y]);
// unless the unit is %, convert the scales and moves to the unit
- if (unit.type == Inkscape::Util::UNIT_TYPE_LINEAR) {
+ if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) {
mh = Quantity::convert(mh, "px", unit);
sh = Quantity::convert(sh, "px", unit);
mv = Quantity::convert(mv, "px", unit);
diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp
index a0b638031..d140cfb21 100644
--- a/src/widgets/stroke-style.cpp
+++ b/src/widgets/stroke-style.cpp
@@ -147,7 +147,8 @@ StrokeStyle::StrokeStyle() :
selectModifiedConn(),
startMarkerConn(),
midMarkerConn(),
- endMarkerConn()
+ endMarkerConn(),
+ _old_unit(NULL)
{
Gtk::HBox *hb;
Gtk::HBox *f = new Gtk::HBox(false, 0);
@@ -199,12 +200,12 @@ StrokeStyle::StrokeStyle() :
Gtk::Widget *us = manage(unitSelector);
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- unitSelector->addUnit(unit_table.getUnit("%"));
+ unitSelector->addUnit(*unit_table.getUnit("%"));
+ _old_unit = unitSelector->getUnit();
if (desktop) {
unitSelector->setUnit(sp_desktop_namedview(desktop)->doc_units->abbr);
- _old_unit = new Inkscape::Util::Unit(*sp_desktop_namedview(desktop)->doc_units);
+ _old_unit = sp_desktop_namedview(desktop)->doc_units;
}
- _old_unit = new Inkscape::Util::Unit(unitSelector->getUnit());
widthSpin->setUnitMenu(unitSelector);
unitChangedConn = unitSelector->signal_changed().connect(sigc::mem_fun(*this, &StrokeStyle::unitChangedCB));
@@ -529,12 +530,12 @@ void StrokeStyle::updateMarkerHist(SPMarkerLoc const which)
*/
void StrokeStyle::unitChangedCB()
{
- Inkscape::Util::Unit new_unit = unitSelector->getUnit();
- if (new_unit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) {
+ Inkscape::Util::Unit const *new_unit = unitSelector->getUnit();
+ if (new_unit->type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) {
widthSpin->set_value(100);
}
- widthSpin->set_value(Inkscape::Util::Quantity::convert(widthSpin->get_value(), *_old_unit, new_unit));
- _old_unit = new Inkscape::Util::Unit(new_unit);
+ widthSpin->set_value(Inkscape::Util::Quantity::convert(widthSpin->get_value(), _old_unit, new_unit));
+ _old_unit = new_unit;
}
/**
@@ -824,21 +825,20 @@ StrokeStyle::updateLine()
} else {
table->set_sensitive(true);
- Inkscape::Util::Unit const *unit = new Inkscape::Util::Unit(unitSelector->getUnit());
-
if (result_sw == QUERY_STYLE_MULTIPLE_AVERAGED) {
unitSelector->setUnit("%");
} else {
// same width, or only one object; no sense to keep percent, switch to absolute
- if (unit->type != Inkscape::Util::UNIT_TYPE_LINEAR) {
+ Inkscape::Util::Unit const *tempunit = unitSelector->getUnit();
+ if (tempunit->type != Inkscape::Util::UNIT_TYPE_LINEAR) {
unitSelector->setUnit(sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units->abbr);
}
}
- unit = new Inkscape::Util::Unit(unitSelector->getUnit());
+ Inkscape::Util::Unit const *unit = unitSelector->getUnit();
if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) {
- double avgwidth = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", *unit);
+ double avgwidth = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", unit);
#if WITH_GTKMM_3_0
(*widthAdj)->set_value(avgwidth);
#else
@@ -964,7 +964,7 @@ StrokeStyle::scaleLine()
double const miterlimit = miterLimitAdj->get_value();
#endif
- Inkscape::Util::Unit const *const unit = new Inkscape::Util::Unit(unitSelector->getUnit());
+ Inkscape::Util::Unit const *const unit = unitSelector->getUnit();
double *dash, offset;
int ndash;
@@ -974,7 +974,7 @@ StrokeStyle::scaleLine()
/* Set stroke width */
double width;
if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) {
- width = Inkscape::Util::Quantity::convert(width_typed, *unit, "px");
+ width = Inkscape::Util::Quantity::convert(width_typed, unit, "px");
} else { // percentage
gdouble old_w = SP_OBJECT(i->data)->style->stroke_width.computed;
width = old_w * width_typed / 100;
diff --git a/src/widgets/stroke-style.h b/src/widgets/stroke-style.h
index 440881c6d..6f0fe583b 100644
--- a/src/widgets/stroke-style.h
+++ b/src/widgets/stroke-style.h
@@ -214,7 +214,7 @@ private:
sigc::connection endMarkerConn;
sigc::connection unitChangedConn;
- Inkscape::Util::Unit *_old_unit;
+ Inkscape::Util::Unit const *_old_unit;
};
} // namespace Inkscape