summaryrefslogtreecommitdiffstats
path: root/src/ui
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 /src/ui
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)
Diffstat (limited to 'src/ui')
-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
19 files changed, 78 insertions, 78 deletions
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;